| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/auth/private/aws_profile.h> |
| 7 |
|
| 8 |
#include <aws/auth/credentials.h> |
| 9 |
#include <aws/common/environment.h> |
| 10 |
#include <aws/common/string.h> |
| 11 |
|
| 12 |
static const struct aws_string *s_profile_get_property_value( |
| 13 |
const struct aws_profile *profile, |
| 14 |
const struct aws_string *property_name) { |
| 15 |
|
| 16 |
const struct aws_profile_property *property = aws_profile_get_property(profile, property_name); |
| 17 |
if (property == NULL) { |
| 18 |
return NULL; |
| 19 |
} |
| 20 |
|
| 21 |
return aws_profile_property_get_value(property); |
| 22 |
} |
| 23 |
|
| 24 |
AWS_STATIC_STRING_FROM_LITERAL(s_access_key_id_profile_var, "aws_access_key_id"); |
| 25 |
AWS_STATIC_STRING_FROM_LITERAL(s_secret_access_key_profile_var, "aws_secret_access_key"); |
| 26 |
AWS_STATIC_STRING_FROM_LITERAL(s_session_token_profile_var, "aws_session_token"); |
| 27 |
AWS_STATIC_STRING_FROM_LITERAL(s_account_id_profile_var, "aws_account_id"); |
| 28 |
|
| 29 |
struct aws_credentials *aws_credentials_new_from_profile( |
| 30 |
struct aws_allocator *allocator, |
| 31 |
const struct aws_profile *profile) { |
| 32 |
const struct aws_string *access_key = s_profile_get_property_value(profile, s_access_key_id_profile_var); |
| 33 |
const struct aws_string *secret_key = s_profile_get_property_value(profile, s_secret_access_key_profile_var); |
| 34 |
if (access_key == NULL || secret_key == NULL) { |
| 35 |
return NULL; |
| 36 |
} |
| 37 |
|
| 38 |
const struct aws_string *session_token = s_profile_get_property_value(profile, s_session_token_profile_var); |
| 39 |
const struct aws_string *account_id = s_profile_get_property_value(profile, s_account_id_profile_var); |
| 40 |
struct aws_credentials_options creds_option = { |
| 41 |
.access_key_id_cursor = aws_byte_cursor_from_string(access_key), |
| 42 |
.secret_access_key_cursor = aws_byte_cursor_from_string(secret_key), |
| 43 |
.session_token_cursor = aws_byte_cursor_from_string(session_token), |
| 44 |
.account_id_cursor = aws_byte_cursor_from_string(account_id), |
| 45 |
.expiration_timepoint_seconds = UINT64_MAX, |
| 46 |
}; |
| 47 |
|
| 48 |
return aws_credentials_new_with_options(allocator, &creds_option); |
| 49 |
} |