Debian Codegraph @

crt/aws-c-sdkutils/include/aws/sdkutils/endpoints_rule_engine.h

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #ifndef AWS_SDKUTILS_ENDPOINTS_RULESET_H
7 #define AWS_SDKUTILS_ENDPOINTS_RULESET_H
8
9 #include <aws/common/byte_buf.h>
10 #include <aws/sdkutils/sdkutils.h>
11
12 AWS_PUSH_SANE_WARNING_LEVEL
13
14 struct aws_endpoints_ruleset;
15 struct aws_partitions_config;
16 struct aws_endpoints_parameter;
17 struct aws_endpoints_rule_engine;
18 struct aws_endpoints_resolved_endpoint;
19 struct aws_endpoints_request_context;
20 struct aws_hash_table;
21
22 enum aws_endpoints_parameter_type {
23 AWS_ENDPOINTS_PARAMETER_STRING,
24 AWS_ENDPOINTS_PARAMETER_BOOLEAN,
25 AWS_ENDPOINTS_PARAMETER_STRING_ARRAY,
26 };
27 enum aws_endpoints_resolved_endpoint_type { AWS_ENDPOINTS_RESOLVED_ENDPOINT, AWS_ENDPOINTS_RESOLVED_ERROR };
28
29 AWS_EXTERN_C_BEGIN
30
31 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_get_supported_ruleset_version(void);
32
33 /**
34 * Warning: The following helpers are intended for use by SDKs that validate correctness of the ruleset at compile time.
35 * The engine sanity checks the provided ruleset, but does not do extensive checking.
36 * Some malformed rulesets might fail in unexpected ways.
37 */
38
39 /*
40 ******************************
41 * Parameter
42 ******************************
43 */
44
45 /*
46 * Value type of parameter.
47 */
48 AWS_SDKUTILS_API enum aws_endpoints_parameter_type aws_endpoints_parameter_get_type(
49 const struct aws_endpoints_parameter *parameter);
50
51 /*
52 * Specifies whether parameter maps to one of SDK built ins (ex. "AWS::Region").
53 * Return is a cursor specifying the name of associated built in.
54 * If there is no mapping, cursor will be empty.
55 * Cursor is guaranteed to be valid for lifetime of paramater.
56 */
57 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_parameter_get_built_in(
58 const struct aws_endpoints_parameter *parameter);
59
60 /*
61 * Default string value.
62 * out_cursor will point to default string value if one exist and will be empty
63 * otherwise.
64 * Cursor is guaranteed to be valid for lifetime of paramater.
65 * Returns AWS_OP_ERR if parameter is not a string.
66 */
67 AWS_SDKUTILS_API int aws_endpoints_parameter_get_default_string(
68 const struct aws_endpoints_parameter *parameter,
69 struct aws_byte_cursor *out_cursor);
70
71 /*
72 * Default boolean value.
73 * out_bool will have pointer to value if default is specified, NULL otherwise.
74 * Owned by parameter.
75 * Returns AWS_OP_ERR if parameter is not a boolean.
76 */
77 AWS_SDKUTILS_API int aws_endpoints_parameter_get_default_boolean(
78 const struct aws_endpoints_parameter *parameter,
79 const bool **out_bool);
80
81 /*
82 * Whether parameter is required.
83 */
84 AWS_SDKUTILS_API bool aws_endpoints_parameter_get_is_required(const struct aws_endpoints_parameter *parameter);
85
86 /*
87 * Returns cursor to parameter documentation.
88 * Cursor is guaranteed to be valid for lifetime of paramater.
89 * Will not be empty as doc is required.
90 */
91 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_parameter_get_documentation(
92 const struct aws_endpoints_parameter *parameter);
93
94 /*
95 * Whether parameter is deprecated.
96 */
97 AWS_SDKUTILS_API bool aws_endpoints_parameters_get_is_deprecated(const struct aws_endpoints_parameter *parameter);
98
99 /*
100 * Deprecation message. Cursor is empty if parameter is not deprecated.
101 * Cursor is guaranteed to be valid for lifetime of paramater.
102 */
103 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_parameter_get_deprecated_message(
104 const struct aws_endpoints_parameter *parameter);
105
106 /*
107 * Deprecated since. Cursor is empty if parameter is not deprecated.
108 * Cursor is guaranteed to be valid for lifetime of paramater.
109 */
110 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_parameter_get_deprecated_since(
111 const struct aws_endpoints_parameter *parameter);
112
113 /*
114 ******************************
115 * Ruleset
116 ******************************
117 */
118
119 /*
120 * Create new ruleset from a json string.
121 * In cases of failure NULL is returned and last error is set.
122 */
123 AWS_SDKUTILS_API struct aws_endpoints_ruleset *aws_endpoints_ruleset_new_from_string(
124 struct aws_allocator *allocator,
125 struct aws_byte_cursor ruleset_json);
126
127 /*
128 * Increment ref count
129 */
130 AWS_SDKUTILS_API struct aws_endpoints_ruleset *aws_endpoints_ruleset_acquire(struct aws_endpoints_ruleset *ruleset);
131
132 /*
133 * Decrement ref count
134 */
135 AWS_SDKUTILS_API struct aws_endpoints_ruleset *aws_endpoints_ruleset_release(struct aws_endpoints_ruleset *ruleset);
136
137 /*
138 * Get ruleset parameters.
139 * Return is a hashtable with paramater name as a key (aws_byte_cursor *) and parameter
140 * (aws_endpoints_parameter *) as a value. Ruleset owns the owns the hashtable and
141 * pointer is valid during ruleset lifetime. Will never return a NULL. In case
142 * there are no parameters in the ruleset, hash table will contain 0 elements.
143 *
144 * Note on usage in bindings:
145 * - this is basically a map from a parameter name to a structure describing parameter
146 * - deep copy all the fields and let language take ownership of data
147 * Consider transforming this into language specific map (dict for python, Map
148 * in Java, std::map in C++, etc...) instead of wrapping it into a custom class.
149 */
150 AWS_SDKUTILS_API const struct aws_hash_table *aws_endpoints_ruleset_get_parameters(
151 struct aws_endpoints_ruleset *ruleset);
152
153 /*
154 * Ruleset version.
155 * Returned pointer is owned by ruleset.
156 * Will not return NULL as version is a required field for ruleset.
157 */
158 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_ruleset_get_version(const struct aws_endpoints_ruleset *ruleset);
159
160 /*
161 * Ruleset service id.
162 * Returned pointer is owned by ruleset.
163 * Can be NULL if not specified in ruleset.
164 */
165 AWS_SDKUTILS_API struct aws_byte_cursor aws_endpoints_ruleset_get_service_id(
166 const struct aws_endpoints_ruleset *ruleset);
167
168 /*
169 ******************************
170 * Rule engine
171 ******************************
172 */
173
174 /**
175 * Create new rule engine for a given ruleset.
176 * In cases of failure NULL is returned and last error is set.
177 */
178 AWS_SDKUTILS_API struct aws_endpoints_rule_engine *aws_endpoints_rule_engine_new(
179 struct aws_allocator *allocator,
180 struct aws_endpoints_ruleset *ruleset,
181 struct aws_partitions_config *partitions_config);
182
183 /*
184 * Increment rule engine ref count.
185 */
186 AWS_SDKUTILS_API struct aws_endpoints_rule_engine *aws_endpoints_rule_engine_acquire(
187 struct aws_endpoints_rule_engine *rule_engine);
188
189 /*
190 * Decrement rule engine ref count.
191 */
192 AWS_SDKUTILS_API struct aws_endpoints_rule_engine *aws_endpoints_rule_engine_release(
193 struct aws_endpoints_rule_engine *rule_engine);
194
195 /*
196 * Creates new request context.
197 * This is basically a property bag containing all request parameter values needed to
198 * resolve endpoint. Parameter value names must match parameter names specified
199 * in ruleset.
200 * Caller is responsible for releasing request context.
201 * Note on usage in bindings:
202 * - Consider exposing it as a custom property bag or a standard map and then
203 * transform it into request context.
204 */
205 AWS_SDKUTILS_API struct aws_endpoints_request_context *aws_endpoints_request_context_new(
206 struct aws_allocator *allocator);
207
208 /*
209 * Increment resolved endpoint ref count.
210 */
211 AWS_SDKUTILS_API struct aws_endpoints_request_context *aws_endpoints_request_context_acquire(
212 struct aws_endpoints_request_context *request_context);
213
214 /*
215 * Decrement resolved endpoint ref count.
216 */
217 AWS_SDKUTILS_API struct aws_endpoints_request_context *aws_endpoints_request_context_release(
218 struct aws_endpoints_request_context *request_context);
219
220 /*
221 * Add string value to request context.
222 * Note: this function will make a copy of the memory backing the cursors.
223 * The function will override any previous value stored in the context with the
224 * same name.
225 */
226 AWS_SDKUTILS_API int aws_endpoints_request_context_add_string(
227 struct aws_allocator *allocator,
228 struct aws_endpoints_request_context *context,
229 struct aws_byte_cursor name,
230 struct aws_byte_cursor value);
231
232 /*
233 * Add boolean value to request context.
234 * The function will override any previous value stored in the context with the
235 * same name.
236 */
237 AWS_SDKUTILS_API int aws_endpoints_request_context_add_boolean(
238 struct aws_allocator *allocator,
239 struct aws_endpoints_request_context *context,
240 struct aws_byte_cursor name,
241 bool value);
242
243 /*
244 * Add string array value to request context.
245 * Note: this function will make a copy of the memory backing the cursors.
246 * The function will override any previous value stored in the context with the
247 * same name.
248 */
249 AWS_SDKUTILS_API int aws_endpoints_request_context_add_string_array(
250 struct aws_allocator *allocator,
251 struct aws_endpoints_request_context *context,
252 struct aws_byte_cursor name,
253 const struct aws_byte_cursor *value_array,
254 size_t len);
255
256 /*
257 * Resolve an endpoint given request context.
258 * Resolved endpoint is returned through out_resolved_endpoint.
259 * In cases of error out_resolved_endpoint is set to NULL and error is returned.
260 * Resolved endpoint is ref counter and caller is responsible for releasing it.
261 */
262 AWS_SDKUTILS_API int aws_endpoints_rule_engine_resolve(
263 struct aws_endpoints_rule_engine *engine,
264 const struct aws_endpoints_request_context *context,
265 struct aws_endpoints_resolved_endpoint **out_resolved_endpoint);
266
267 /*
268 * Increment resolved endpoint ref count.
269 */
270 AWS_SDKUTILS_API struct aws_endpoints_resolved_endpoint *aws_endpoints_resolved_endpoint_acquire(
271 struct aws_endpoints_resolved_endpoint *resolved_endpoint);
272
273 /*
274 * Decrement resolved endpoint ref count.
275 */
276 AWS_SDKUTILS_API struct aws_endpoints_resolved_endpoint *aws_endpoints_resolved_endpoint_release(
277 struct aws_endpoints_resolved_endpoint *resolved_endpoint);
278
279 /*
280 * Get type of resolved endpoint.
281 */
282 AWS_SDKUTILS_API enum aws_endpoints_resolved_endpoint_type aws_endpoints_resolved_endpoint_get_type(
283 const struct aws_endpoints_resolved_endpoint *resolved_endpoint);
284
285 /*
286 * Get url for the resolved endpoint.
287 * Valid only if resolved endpoint has endpoint type and will error otherwise.
288 */
289 AWS_SDKUTILS_API int aws_endpoints_resolved_endpoint_get_url(
290 const struct aws_endpoints_resolved_endpoint *resolved_endpoint,
291 struct aws_byte_cursor *out_url);
292
293 /*
294 * Get properties for the resolved endpoint.
295 * Note: properties is a json string containing additional data for a given
296 * endpoint. Data is not typed and is not guaranteed to change in the future.
297 * For use at callers discretion.
298 * Valid only if resolved endpoint has endpoint type and will error otherwise.
299 */
300 AWS_SDKUTILS_API int aws_endpoints_resolved_endpoint_get_properties(
301 const struct aws_endpoints_resolved_endpoint *resolved_endpoint,
302 struct aws_byte_cursor *out_properties);
303
304 /*
305 * Get headers for the resolved endpoint.
306 * out_headers type is aws_hash_table with (aws_string *) as key
307 * and (aws_array_list * of aws_string *) as value.
308 * Note on usage in bindings:
309 * - this is a map to a list of strings and can be implemented as such in the
310 * target language with deep copy of all underlying strings.
311 * Valid only if resolved endpoint has endpoint type and will error otherwise.
312 */
313 AWS_SDKUTILS_API int aws_endpoints_resolved_endpoint_get_headers(
314 const struct aws_endpoints_resolved_endpoint *resolved_endpoint,
315 const struct aws_hash_table **out_headers);
316
317 /*
318 * Get error for the resolved endpoint.
319 * Valid only if resolved endpoint has error type and will error otherwise.
320 */
321 AWS_SDKUTILS_API int aws_endpoints_resolved_endpoint_get_error(
322 const struct aws_endpoints_resolved_endpoint *resolved_endpoint,
323 struct aws_byte_cursor *out_error);
324
325 AWS_EXTERN_C_END
326 AWS_POP_SANE_WARNING_LEVEL
327
328 #endif /* AWS_SDKUTILS_ENDPOINTS_RULESET_H */