Skip to content

Commit

Permalink
Normalize section keys to lowercase
Browse files Browse the repository at this point in the history
This is to match the behavior of the parsing in Python, and the boto
based AWS CLI, where the keys are normalized to lowercase.

We had a case where things were working using the CLI but when we tried
to do the same action through the Go SDK it didn't work because we had
UPPERCASED the access_key_id.
  • Loading branch information
gaqzi committed Feb 28, 2020
1 parent 0c78da5 commit 11b9ba0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions aws/external/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ func TestLoadSharedConfigFromFile(t *testing.T) {
Err: nil,
},
},
{
Profile: "with_mixed_case_keys",
Expected: SharedConfig{
Credentials: aws.Credentials{
AccessKeyID: "accessKey",
SecretAccessKey: "secret",
Source: fmt.Sprintf("SharedConfigCredentials: %s", testConfigFilename),
},
},
},
}

for i, c := range cases {
Expand Down
4 changes: 4 additions & 0 deletions aws/external/testdata/shared_config
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ s3_use_arn_region=true

[endpoint_discovery]
endpoint_discovery_enabled=true

[with_mixed_case_keys]
aWs_AcCeSs_kEy_ID: accessKey
aWs_SecrEt_AccEsS_kEY: secret
4 changes: 4 additions & 0 deletions internal/ini/testdata/valid/mixed_case_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[with_mixed_case_keys]
sTring_Value = secret
iNt_Value = 60
flOAt_Value = 12.3
7 changes: 7 additions & 0 deletions internal/ini/testdata/valid/mixed_case_keys_expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"with_mixed_case_keys": {
"int_value": 60,
"string_value": "secret",
"float_value": 12.3
}
}
2 changes: 1 addition & 1 deletion internal/ini/testdata/valid/utf_8_profile_expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ʃʉʍΡιξ": {
"ϰϪϧ": "Ϯϴϖ",
"ϰϫϧ": "Ϯϴϖ",
"ϝϧ": "ϟΞ΅"
}
}
3 changes: 2 additions & 1 deletion internal/ini/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ini
import (
"fmt"
"sort"
"strings"
)

// Visitor is an interface used by walkers that will
Expand Down Expand Up @@ -60,7 +61,7 @@ func (v *DefaultVisitor) VisitExpr(expr AST) error {
return err
}

t.values[key] = v
t.values[strings.ToLower(key)] = v
default:
return NewParseError(fmt.Sprintf("unsupported expression %v", expr))
}
Expand Down

0 comments on commit 11b9ba0

Please sign in to comment.