aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
RuleEngine.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/Types.h>
8
9struct aws_endpoints_rule_engine;
10struct aws_endpoints_request_context;
11struct aws_endpoints_resolved_endpoint;
12
13namespace Aws
14{
15 namespace Crt
16 {
17 namespace Endpoints
18 {
19 /*
20 * Add parameter to the context.
21 * Only string and boolean values are supported.
22 * Adding parameter several times with the same name will overwrite
23 * previous values.
24 */
26 {
27 public:
28 RequestContext(Allocator *allocator = ApiAllocator()) noexcept;
30
31 /* TODO: move/copy semantics */
32 RequestContext(const RequestContext &) = delete;
36
40 operator bool() const noexcept { return m_requestContext != nullptr; }
41
42 /*
43 * Add string parameter.
44 * True if added successfully and false if failed.
45 * Aws::Crt::LastError() can be used to retrieve failure error code.
46 */
47 bool AddString(const ByteCursor &name, const ByteCursor &value);
48
49 /*
50 * Add boolean parameter.
51 * True if added successfully and false if failed.
52 * Aws::Crt::LastError() can be used to retrieve failure error code.
53 */
54 bool AddBoolean(const ByteCursor &name, bool value);
55
56 /*
57 * Add string array parameter.
58 * True if added successfully and false if failed.
59 * Aws::Crt::LastError() can be used to retrieve failure error code.
60 */
61 bool AddStringArray(const ByteCursor &name, const Vector<ByteCursor> &value);
62
64 aws_endpoints_request_context *GetNativeHandle() const noexcept { return m_requestContext; }
65
66 private:
67 Allocator *m_allocator;
68 aws_endpoints_request_context *m_requestContext;
69 };
70
71 /*
72 * Outcome of Endpoint Resolution.
73 * Outcome can be either endpoint (IsEndpoint) or error (IsError).
74 * Endpoint outcome means that engine was able to resolve context to
75 * an endpoint and outcome can have the following fields defined:
76 * - Url (required) - resolved url
77 * - Headers (optional) - additional headers to be included with request
78 * - Properties (optional) - custom list of properties associated
79 * with request (json blob to be interpreted by the caller.)
80 *
81 * Error outcome means that context could not be resolved to an endpoint.
82 * Outcome will have following fields:
83 * - Error (required) - error message providing more info on why
84 * endpoint could not be resolved.
85 */
87 {
88 public:
90
91 /* TODO: move/copy semantics */
94 ResolutionOutcome(ResolutionOutcome &&toMove) noexcept;
96
97 bool IsEndpoint() const noexcept;
98 bool IsError() const noexcept;
99
100 /*
101 * Endpoint properties.
102 * Note: following fields are none if outcome is error.
103 * Headers and Properties are optional and could also be None.
104 */
105 Optional<StringView> GetUrl() const;
106 Optional<StringView> GetProperties() const;
107 Optional<UnorderedMap<StringView, Vector<StringView>>> GetHeaders() const;
108
109 /*
110 * Error properties.
111 * Note: following fields are none if outcome is error.
112 */
113 Optional<StringView> GetError() const;
114
118 operator bool() const noexcept { return m_resolvedEndpoint != nullptr; }
119
121 ResolutionOutcome(aws_endpoints_resolved_endpoint *impl);
122
123 private:
124 aws_endpoints_resolved_endpoint *m_resolvedEndpoint;
125 };
126
131 {
132 public:
134 const ByteCursor &rulesetCursor,
135 const ByteCursor &partitionsCursor,
136 Allocator *allocator = ApiAllocator()) noexcept;
137 ~RuleEngine();
138
139 RuleEngine(const RuleEngine &) = delete;
140 RuleEngine &operator=(const RuleEngine &) = delete;
141 RuleEngine(RuleEngine &&) = delete;
143
147 operator bool() const noexcept { return m_ruleEngine != nullptr; }
148
149 /*
150 * Resolves rules against the provided context.
151 * If successful return will have resolution outcome.
152 * If not, return will be none and Aws::Crt::LastError() can be
153 * used to retrieve CRT error code.
154 */
155 Optional<ResolutionOutcome> Resolve(const RequestContext &context) const;
156
157 private:
158 aws_endpoints_rule_engine *m_ruleEngine;
159 };
160 } // namespace Endpoints
161 } // namespace Crt
162} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition RuleEngine.h:26
RequestContext & operator=(const RequestContext &)=delete
RequestContext(const RequestContext &)=delete
RequestContext & operator=(RequestContext &&)=delete
RequestContext(RequestContext &&)=delete
Definition RuleEngine.h:87
ResolutionOutcome & operator=(const ResolutionOutcome &)=delete
ResolutionOutcome(const ResolutionOutcome &)=delete
Definition RuleEngine.h:131
RuleEngine(const RuleEngine &)=delete
RuleEngine & operator=(const RuleEngine &)=delete
RuleEngine & operator=(RuleEngine &&)=delete
RuleEngine(RuleEngine &&)=delete
Definition Optional.h:19
Definition StringView.h:33
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
std::unordered_map< K, V, std::hash< K >, std::equal_to< K >, StlAllocator< std::pair< const K, V > > > UnorderedMap
Definition Types.h:50
std::vector< T, StlAllocator< T > > Vector
Definition Types.h:53
Definition Allocator.h:11