Debian Codegraph @

crt/aws-c-auth/include/aws/auth/private/credentials_utils.h

raw symbols SCIP
1 #ifndef AWS_AUTH_CREDENTIALS_PRIVATE_H
2 #define AWS_AUTH_CREDENTIALS_PRIVATE_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/auth/auth.h>
10 #include <aws/auth/credentials.h>
11 #include <aws/http/connection_manager.h>
12 #include <aws/io/retry_strategy.h>
13
14 struct aws_http_connection;
15 struct aws_http_connection_manager;
16 struct aws_http_make_request_options;
17 struct aws_http_stream;
18 struct aws_json_value;
19 struct aws_profile;
20
21 /*
22 * Internal struct tracking an asynchronous credentials query.
23 * Used by both the cached provider and the test mocks.
24 *
25 */
26 struct aws_credentials_query {
27 struct aws_linked_list_node node;
28 struct aws_credentials_provider *provider;
29 aws_on_get_credentials_callback_fn *callback;
30 void *user_data;
31 };
32
33 typedef struct aws_http_connection_manager *(
34 aws_http_connection_manager_new_fn)(struct aws_allocator *allocator,
35 const struct aws_http_connection_manager_options *options);
36 typedef void(aws_http_connection_manager_release_fn)(struct aws_http_connection_manager *manager);
37 typedef void(aws_http_connection_manager_acquire_connection_fn)(
38 struct aws_http_connection_manager *manager,
39 aws_http_connection_manager_on_connection_setup_fn *callback,
40 void *user_data);
41 typedef int(aws_http_connection_manager_release_connection_fn)(
42 struct aws_http_connection_manager *manager,
43 struct aws_http_connection *connection);
44 typedef struct aws_http_stream *(
45 aws_http_connection_make_request_fn)(struct aws_http_connection *client_connection,
46 const struct aws_http_make_request_options *options);
47 typedef int(aws_http_stream_activate_fn)(struct aws_http_stream *stream);
48 typedef struct aws_http_connection *(aws_http_stream_get_connection_fn)(const struct aws_http_stream *stream);
49
50 typedef int(aws_http_stream_get_incoming_response_status_fn)(const struct aws_http_stream *stream, int *out_status);
51 typedef void(aws_http_stream_release_fn)(struct aws_http_stream *stream);
52 typedef void(aws_http_connection_close_fn)(struct aws_http_connection *connection);
53
54 /*
55 * Table of all downstream http functions used by the credentials providers that make http calls. Allows for simple
56 * mocking.
57 */
58 struct aws_auth_http_system_vtable {
59 aws_http_connection_manager_new_fn *aws_http_connection_manager_new;
60 aws_http_connection_manager_release_fn *aws_http_connection_manager_release;
61
62 aws_http_connection_manager_acquire_connection_fn *aws_http_connection_manager_acquire_connection;
63 aws_http_connection_manager_release_connection_fn *aws_http_connection_manager_release_connection;
64
65 aws_http_connection_make_request_fn *aws_http_connection_make_request;
66 aws_http_stream_activate_fn *aws_http_stream_activate;
67 aws_http_stream_get_connection_fn *aws_http_stream_get_connection;
68 aws_http_stream_get_incoming_response_status_fn *aws_http_stream_get_incoming_response_status;
69 aws_http_stream_release_fn *aws_http_stream_release;
70
71 aws_http_connection_close_fn *aws_http_connection_close;
72
73 int (*aws_high_res_clock_get_ticks)(uint64_t *timestamp);
74 };
75
76 enum aws_parse_credentials_expiration_format {
77 AWS_PCEF_STRING_ISO_8601_DATE,
78 AWS_PCEF_NUMBER_UNIX_EPOCH,
79 AWS_PCEF_NUMBER_UNIX_EPOCH_MS,
80 };
81
82 struct aws_parse_credentials_from_json_doc_options {
83 const char *access_key_id_name;
84 const char *secret_access_key_name;
85 const char *token_name;
86 const char *expiration_name;
87 const char *account_id_name;
88 const char *top_level_object_name;
89 enum aws_parse_credentials_expiration_format expiration_format;
90 bool token_required;
91 bool expiration_required;
92 };
93
94 AWS_EXTERN_C_BEGIN
95
96 /*
97 * Misc. credentials-related APIs
98 */
99
100 AWS_AUTH_API
101 void aws_credentials_query_init(
102 struct aws_credentials_query *query,
103 struct aws_credentials_provider *provider,
104 aws_on_get_credentials_callback_fn *callback,
105 void *user_data);
106
107 AWS_AUTH_API
108 void aws_credentials_query_clean_up(struct aws_credentials_query *query);
109
110 AWS_AUTH_API
111 void aws_credentials_provider_init_base(
112 struct aws_credentials_provider *provider,
113 struct aws_allocator *allocator,
114 struct aws_credentials_provider_vtable *vtable,
115 void *impl);
116
117 AWS_AUTH_API
118 void aws_credentials_provider_destroy(struct aws_credentials_provider *provider);
119
120 AWS_AUTH_API
121 void aws_credentials_provider_invoke_shutdown_callback(struct aws_credentials_provider *provider);
122
123 /**
124 * This API is used internally to parse credentials from json document.
125 * It _ONLY_ parses the first level of json structure. json document like
126 * this will produce a valid credentials:
127 {
128 "accessKeyId" : "...",
129 "secretAccessKey" : "...",
130 "Token" : "...",
131 "expiration" : "2019-05-29T00:21:43Z"
132 }
133 * but json document like this won't:
134 {
135 "credentials": {
136 "accessKeyId" : "...",
137 "secretAccessKey" : "...",
138 "sessionToken" : "...",
139 "expiration" : "2019-05-29T00:21:43Z"
140 }
141 }
142 * In general, the keys' names of credentials in json document are:
143 * "AccessKeyId", "SecretAccessKey", "Token" and "Expiration",
144 * but there are cases services use different keys like "sessionToken".
145 * A valid credentials must have "access key" and "secrete access key".
146 * For some services, token and expiration are not required.
147 * So in this API, the keys are provided by callers and this API will
148 * perform a case insensitive search.
149 */
150 AWS_AUTH_API
151 struct aws_credentials *aws_parse_credentials_from_aws_json_object(
152 struct aws_allocator *allocator,
153 struct aws_json_value *document_root,
154 const struct aws_parse_credentials_from_json_doc_options *options);
155
156 /**
157 * This API is similar to aws_parse_credentials_from_aws_json_object,
158 * except it accepts a char buffer json document as it's input.
159 */
160 AWS_AUTH_API
161 struct aws_credentials *aws_parse_credentials_from_json_document(
162 struct aws_allocator *allocator,
163 struct aws_byte_cursor json_document,
164 const struct aws_parse_credentials_from_json_doc_options *options);
165
166 AWS_AUTH_API
167 enum aws_retry_error_type aws_credentials_provider_compute_retry_error_type(int response_code, int error_code);
168
169 /*
170 * If an endpoint override is configured, use that. Otherwise do the following:
171 * Construct an endpoint in the format of service_name_host.region.amazonaws.com.
172 * If the region is cn-north-1 or cn-northwest-1, .cn is appended to support China-specific regional endpoints.
173 * Suffix_override will override amazonaws.com to be the suffix of your choice i.e aws.amazon.com.
174 * swap_region_and_service_name will swap the service name and region (i.e., service.us-east-1 to us-east-1.service)
175 * when constructing the endpoint to address endpoint customization present in some services.
176 *
177 * To configure the endpoint override, check the
178 * https://docs.aws.amazon.com/sdkref/latest/guide/feature-ss-endpoints.html.
179 */
180 AWS_AUTH_API
181 int aws_credentials_provider_construct_endpoint(
182 struct aws_allocator *allocator,
183 struct aws_string **out_endpoint,
184 const struct aws_string *region,
185 const struct aws_string *service_name_host,
186 const struct aws_string *service_name_env,
187 const struct aws_string *service_name_property,
188 const struct aws_profile_collection *profile_collection,
189 const struct aws_profile *profile,
190 const struct aws_byte_cursor *suffix_override,
191 bool swap_region_and_service_name);
192
193 /*
194 * Loads an aws config profile collection
195 */
196 AWS_AUTH_API
197 struct aws_profile_collection *aws_load_profile_collection_from_config_file(
198 struct aws_allocator *allocator,
199 struct aws_byte_cursor config_file_name_override);
200
201 /*
202 * Resolve region from environment in the following order:
203 * 1. AWS_REGION
204 * 2. AWS_DEFAULT_REGION
205 */
206 AWS_AUTH_API
207 struct aws_string *aws_credentials_provider_resolve_region_from_env(struct aws_allocator *allocator);
208
209 /*
210 * Parses account_id from arn with the format arn:partition:service:region:account-id:resource-id
211 * Returns an empty cursor if the account_id is not present or unable to parse the account_id
212 */
213 AWS_AUTH_API
214 struct aws_byte_cursor aws_parse_account_id_from_arn(struct aws_byte_cursor arn);
215
216 AWS_EXTERN_C_END
217
218 #endif /* AWS_AUTH_CREDENTIALS_PRIVATE_H */