-
Notifications
You must be signed in to change notification settings - Fork 65
Fix default profile handling when parsing AWS configuration files #727
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
Changes from 5 commits
9ecfe5a
a30b1b6
b21f568
06f947c
b8c5231
b2a6268
464909b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| @testset "_aws_profile_config" begin | ||
| using AWS: _aws_profile_config | ||
|
|
||
| @testset "source profile" begin | ||
| #! format: off | ||
| buffer = IOBuffer( | ||
| """ | ||
| [profile test] | ||
| output = json | ||
| region = us-east-1 | ||
|
|
||
| [profile test:dev] | ||
| source_profile = test | ||
| role_arn = arn:aws:iam::123456789000:role/Dev | ||
|
|
||
| [profile test:sub-dev] | ||
|
||
| source_profile = test:dev | ||
| role_arn = arn:aws:iam::123456789000:role/SubDev | ||
| """ | ||
| ) | ||
| #! format: on | ||
| ini = Inifile() | ||
| read(ini, buffer) | ||
|
|
||
| # Only the fields from profile "test" | ||
| config = _aws_profile_config(ini, "test") | ||
| @test keys(config) ⊆ Set(["output", "region"]) | ||
| @test config["output"] == "json" | ||
| @test config["region"] == "us-east-1" | ||
|
|
||
| # Combine the profile "test:dev" section with fields from profile "test" | ||
| config = _aws_profile_config(ini, "test:dev") | ||
| @test keys(config) ⊆ Set(["output", "region", "role_arn"]) | ||
| @test config["output"] == "json" | ||
| @test config["region"] == "us-east-1" | ||
| @test config["role_arn"] == "arn:aws:iam::123456789000:role/Dev" | ||
|
|
||
| # Ensure we haven't mutated the contents of the `ini` | ||
| section = sections(ini)["profile test:dev"] | ||
| @test !haskey(section, "region") | ||
| @test !haskey(section, "output") | ||
|
|
||
| # Conflicting keys should use the first defined entry | ||
| config = _aws_profile_config(ini, "test:sub-dev") | ||
| @test keys(config) ⊆ Set(["output", "region", "role_arn"]) | ||
| @test config["output"] == "json" | ||
| @test config["region"] == "us-east-1" | ||
| @test config["role_arn"] == "arn:aws:iam::123456789000:role/SubDev" | ||
|
|
||
| # Ensure we haven't mutated the contents of the `ini` | ||
| section = sections(ini)["profile test:sub-dev"] | ||
| @test !haskey(section, "region") | ||
| @test !haskey(section, "output") | ||
| end | ||
|
|
||
| # AWS CLI (version v2.27.15) will use "profile default" over "default" when both are | ||
| # defined within the configuration. This is true when `AWS_PROFILE` is unset or | ||
| # `AWS_PROFILE="default". | ||
| @testset "default profile" begin | ||
| #! format: off | ||
| buffer = IOBuffer( | ||
| """ | ||
| [default] | ||
| region = default-1 | ||
|
|
||
| [profile default] | ||
| region = default-2 | ||
| """ | ||
| ) | ||
| #! format: on | ||
| ini = Inifile() | ||
| read(ini, buffer) | ||
|
|
||
| config = _aws_profile_config(ini, "default") | ||
| @test config["region"] == "default-2" | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the previous logic was to prefer
defaultoverprofile defaultwhich deviates from the AWS CLI preference.