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