Debian Codegraph @

crt/aws-c-s3/include/aws/s3/private/s3express_credentials_provider_impl.h

raw symbols SCIP
1 #ifndef AWS_S3EXPRESS_CREDENTIALS_PROVIDER_IMPL_H
2 #define AWS_S3EXPRESS_CREDENTIALS_PROVIDER_IMPL_H
3
4 #include <aws/common/hash_table.h>
5 #include <aws/common/mutex.h>
6 #include <aws/common/ref_count.h>
7 #include <aws/s3/s3_client.h>
8 #include <aws/s3/s3express_credentials_provider.h>
9
10 struct aws_cache;
11
12 /**
13 * Everything in the session should ONLY be accessed with lock HELD
14 */
15 struct aws_s3express_session {
16 struct aws_allocator *allocator;
17 /* The hash key for the table storing creator and session. */
18 struct aws_string *hash_key;
19
20 /* The s3express credentials cached for the session */
21 struct aws_credentials *s3express_credentials;
22
23 /* Pointer to the creator if the session is in process creating */
24 struct aws_s3express_session_creator *creator;
25
26 /* The region and host of the session */
27 struct aws_string *region;
28 struct aws_string *host;
29
30 struct aws_http_headers *headers;
31 bool inactive;
32
33 /* Only used for mock tests */
34 struct aws_s3express_credentials_provider_impl *impl;
35 };
36
37 struct aws_s3express_credentials_provider_impl {
38 struct aws_s3_client *client;
39
40 /* Internal Refcount to make sure the provider out lives all the context. */
41 struct aws_ref_count internal_ref;
42
43 struct aws_task *bg_refresh_task;
44 struct aws_event_loop *bg_event_loop;
45
46 const struct aws_credentials *default_original_credentials;
47 struct aws_credentials_provider *default_original_credentials_provider;
48
49 struct {
50 /* Protected by the impl lock */
51 struct aws_mutex lock;
52 /**
53 * Store the session creators in process.
54 * `struct aws_string *` as Key. `struct aws_s3express_session_creator *` as Value
55 */
56 struct aws_hash_table session_creator_table;
57 /**
58 * An LRU cache to store all the sessions.
59 * `struct aws_string *` as Key. `struct aws_s3express_session *` as Value
60 **/
61 struct aws_cache *cache;
62 bool destroying;
63 } synced_data;
64
65 struct {
66 /* Overrides for testing purpose. */
67
68 struct aws_uri *endpoint_override;
69 uint64_t bg_refresh_secs_override;
70
71 bool (*s3express_session_is_valid_override)(struct aws_s3express_session *session, uint64_t now_seconds);
72 bool (*s3express_session_about_to_expire_override)(struct aws_s3express_session *session, uint64_t now_seconds);
73
74 /* The callback to be invoked before the real meta request finished callback for provider */
75 aws_s3_meta_request_finish_fn *meta_request_finished_overhead;
76 } mock_test;
77 };
78
79 /**
80 * Configuration options for the default S3 Express credentials provider
81 */
82 struct aws_s3express_credentials_provider_default_options {
83 /**
84 * The S3 client to fetch credentials.
85 * Note, the client is not owned by the provider, user should keep the s3 client outlive the provider. */
86 struct aws_s3_client *client;
87
88 /* Optional callback for shutdown complete of the provider */
89 aws_simple_completion_callback *shutdown_complete_callback;
90 void *shutdown_user_data;
91
92 struct {
93 uint64_t bg_refresh_secs_override;
94 } mock_test;
95 };
96
97 AWS_EXTERN_C_BEGIN
98 /**
99 * Create the default S3 Express credentials provider.
100 *
101 * @param allocator
102 * @return
103 */
104 AWS_S3_API
105 struct aws_s3express_credentials_provider *aws_s3express_credentials_provider_new_default(
106 struct aws_allocator *allocator,
107 const struct aws_s3express_credentials_provider_default_options *options);
108
109 /**
110 * Encodes the hash key in the format: [host_value][hash_of_credentials_and_headers]
111 *
112 * The hash_of_credentials_and_headers is calculated as follows:
113 * 1. Concatenate: [access_key][secret_access_key][headers]
114 * where headers = ",header_name1:header_value1,header_name2:header_value2..."
115 * 2. Generates SHA256 hash of the concatenated string
116 */
117 AWS_S3_API
118 struct aws_string *aws_encode_s3express_hash_key_new(
119 struct aws_allocator *allocator,
120 const struct aws_credentials *original_credentials,
121 struct aws_byte_cursor host_value,
122 struct aws_http_headers *headers);
123
124 AWS_EXTERN_C_END
125 #endif /* AWS_S3EXPRESS_CREDENTIALS_PROVIDER_IMPL_H */