Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the behavior for profile override #30

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions source/aws_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,14 +1541,17 @@ struct aws_string *aws_get_config_file_path(
AWS_STATIC_STRING_FROM_LITERAL(s_default_profile_env_variable_name, "AWS_PROFILE");

struct aws_string *aws_get_profile_name(struct aws_allocator *allocator, const struct aws_byte_cursor *override_name) {

/**
* The default profile must be used if the user does NOT specify a profile.
* the default profile can be overridden using the AWS_PROFILE environment variable.
*/
TingDaoK marked this conversation as resolved.
Show resolved Hide resolved
struct aws_string *profile_name = NULL;

if (aws_get_environment_value(allocator, s_default_profile_env_variable_name, &profile_name) ||
profile_name == NULL) {
if (override_name != NULL && override_name->ptr != NULL) {
profile_name = aws_string_new_from_array(allocator, override_name->ptr, override_name->len);
} else {
if (override_name != NULL && override_name->ptr != NULL) {
profile_name = aws_string_new_from_array(allocator, override_name->ptr, override_name->len);
} else {
/* Use the default profile. Override the default profile with AWS_PROFILE environment variable if exist */
if (aws_get_environment_value(allocator, s_default_profile_env_variable_name, &profile_name) ||
profile_name == NULL) {
TingDaoK marked this conversation as resolved.
Show resolved Hide resolved
profile_name = aws_string_new_from_string(allocator, s_default_profile_name);
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/aws_profile_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,8 @@ AWS_STATIC_STRING_FROM_LITERAL(s_profile_override, "NotTheDefault");

static int s_profile_override_test(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

/* Make sure the environment doesn't affect this test */
aws_unset_environment_value(s_profile_env_var);
/* The envrionment value should only override the default when user not set one */
aws_set_environment_value(s_profile_env_var, s_profile_override);

struct aws_byte_cursor override_cursor = aws_byte_cursor_from_string(s_profile_override);
struct aws_string *profile_name = aws_get_profile_name(allocator, &override_cursor);
Expand Down