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 all commits
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
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