Skip to content

Commit

Permalink
update the behavior for profile override (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed May 30, 2023
1 parent 4047b61 commit df511a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
19 changes: 12 additions & 7 deletions source/aws_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,14 +1541,19 @@ 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) {

/**
* Profile name is resolved in the following order.
* 1. If the override_path variable is provided.
* 2. Check `AWS_PROFILE` environment variable and use the value if it is not empty.
* 3. Use "default". */
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 {
/* Try to fetch profile from AWS_PROFILE environment variable */
aws_get_environment_value(allocator, s_default_profile_env_variable_name, &profile_name);
/* Use default profile if it doesn't exist. */
if (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 df511a1

Please sign in to comment.