Skip to content

Commit

Permalink
update the behavior for profile override
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed May 24, 2023
1 parent 4047b61 commit ed5ff8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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.
*/
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) {
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

0 comments on commit ed5ff8d

Please sign in to comment.