Debian Codegraph @

crt/aws-c-auth/source/credentials_provider_static.c

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 #include <aws/auth/credentials.h>
7
8 #include <aws/auth/private/credentials_utils.h>
9
10 static int s_static_credentials_provider_get_credentials_async(
11 struct aws_credentials_provider *provider,
12 aws_on_get_credentials_callback_fn callback,
13 void *user_data) {
14
15 struct aws_credentials *credentials = provider->impl;
16
17 AWS_LOGF_INFO(
18 AWS_LS_AUTH_CREDENTIALS_PROVIDER,
19 "(id=%p) Static credentials provider successfully sourced credentials",
20 (void *)provider);
21 callback(credentials, AWS_ERROR_SUCCESS, user_data);
22
23 return AWS_OP_SUCCESS;
24 }
25
26 static void s_static_credentials_provider_destroy(struct aws_credentials_provider *provider) {
27 struct aws_credentials *credentials = provider->impl;
28
29 aws_credentials_release(credentials);
30 aws_credentials_provider_invoke_shutdown_callback(provider);
31 aws_mem_release(provider->allocator, provider);
32 }
33
34 /*
35 * shared across all providers that do not need to do anything special on shutdown
36 */
37
38 static struct aws_credentials_provider_vtable s_aws_credentials_provider_static_vtable = {
39 .get_credentials = s_static_credentials_provider_get_credentials_async,
40 .destroy = s_static_credentials_provider_destroy,
41 };
42
43 struct aws_credentials_provider *aws_credentials_provider_new_static(
44 struct aws_allocator *allocator,
45 const struct aws_credentials_provider_static_options *options) {
46
47 struct aws_credentials_provider *provider = aws_mem_acquire(allocator, sizeof(struct aws_credentials_provider));
48 if (provider == NULL) {
49 return NULL;
50 }
51
52 AWS_ZERO_STRUCT(*provider);
53 struct aws_credentials_options creds_option = {
54 .access_key_id_cursor = options->access_key_id,
55 .secret_access_key_cursor = options->secret_access_key,
56 .session_token_cursor = options->session_token,
57 .account_id_cursor = options->account_id,
58 .expiration_timepoint_seconds = UINT64_MAX,
59 };
60 struct aws_credentials *credentials = aws_credentials_new_with_options(allocator, &creds_option);
61 if (credentials == NULL) {
62 goto on_new_credentials_failure;
63 }
64
65 aws_credentials_provider_init_base(provider, allocator, &s_aws_credentials_provider_static_vtable, credentials);
66
67 provider->shutdown_options = options->shutdown_options;
68
69 return provider;
70
71 on_new_credentials_failure:
72
73 aws_mem_release(allocator, provider);
74
75 return NULL;
76 }