Skip to content

Commit 5c1b48d

Browse files
authored
feat: ini2 parser (#2365)
1 parent 5a1ec8a commit 5c1b48d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+703
-2912
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "7d0bbc14-77cd-4cef-a695-8c9762ace056",
3+
"type": "feature",
4+
"description": "Replace the legacy config parser with a modern, less-strict implementation. Parsing failures within a section will now simply ignore the invalid line rather than silently drop the entire section.",
5+
"modules": [
6+
"config",
7+
"internal/ini"
8+
]
9+
}

config/config_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"testing"
78

89
"github.com/aws/aws-sdk-go-v2/aws"
@@ -146,3 +147,66 @@ func TestLoadDefaultConfig(t *testing.T) {
146147
t.Fatal("expect error when optFn returns error, got nil")
147148
}
148149
}
150+
151+
func BenchmarkLoadProfile1(b *testing.B) {
152+
benchConfigLoad(b, 1)
153+
}
154+
155+
func BenchmarkLoadProfile10(b *testing.B) {
156+
benchConfigLoad(b, 10)
157+
}
158+
159+
func BenchmarkLoadProfile100(b *testing.B) {
160+
benchConfigLoad(b, 100)
161+
}
162+
163+
func BenchmarkLoadProfile1000(b *testing.B) {
164+
benchConfigLoad(b, 1000)
165+
}
166+
167+
func benchConfigLoad(b *testing.B, n int) {
168+
f, err := generateProfiles(n)
169+
if err != nil {
170+
b.Fatal(err)
171+
}
172+
173+
defer os.Remove(f)
174+
opt := WithSharedConfigFiles([]string{f})
175+
176+
b.ResetTimer()
177+
for n := 0; n < b.N; n++ {
178+
LoadDefaultConfig(context.Background(), opt)
179+
}
180+
}
181+
182+
const profileTemplate = `
183+
[profile role%d]
184+
tool_sso_start_url = https://example.awsapps.com/start
185+
tool_sso_region = us-west-2
186+
tool_sso_account_id = 12345678901234
187+
tool_sso_role_name = some_role_name
188+
tool_generated_from = some_tool
189+
credential_process = some_tool credential-process
190+
`
191+
192+
func generateProfiles(n int) (string, error) {
193+
f, err := os.CreateTemp("", fmt.Sprintf("aws-bench-config-%d-*", n))
194+
if err != nil {
195+
return "", err
196+
}
197+
198+
for i := 0; i < n; i++ {
199+
if _, err := fmt.Fprintf(f, profileTemplate, n); err != nil {
200+
f.Close()
201+
os.Remove(f.Name())
202+
return "", err
203+
}
204+
}
205+
206+
if err := f.Close(); err != nil {
207+
os.Remove(f.Name())
208+
return "", err
209+
}
210+
211+
return f.Name(), nil
212+
}

config/shared_config_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222
var _ regionProvider = (*SharedConfig)(nil)
2323

2424
var (
25-
testConfigFilename = filepath.Join("testdata", "shared_config")
26-
testConfigOtherFilename = filepath.Join("testdata", "shared_config_other")
27-
testCredentialsFilename = filepath.Join("testdata", "shared_credentials")
28-
testConfigLeadingWSFilename1 = filepath.Join("testdata", "leading_ws")
29-
testConfigLeadingWSFilename2 = filepath.Join("testdata", "leading_ws_trailing_nl")
25+
testConfigFilename = filepath.Join("testdata", "shared_config")
26+
testConfigOtherFilename = filepath.Join("testdata", "shared_config_other")
27+
testCredentialsFilename = filepath.Join("testdata", "shared_credentials")
3028
)
3129

3230
func TestNewSharedConfig(t *testing.T) {
@@ -140,9 +138,10 @@ func TestNewSharedConfig(t *testing.T) {
140138
"Invalid INI file": {
141139
ConfigFilenames: []string{filepath.Join("testdata", "shared_config_invalid_ini")},
142140
Profile: "profile_name",
143-
Err: SharedConfigLoadError{
144-
Filename: filepath.Join("testdata", "shared_config_invalid_ini"),
145-
Err: fmt.Errorf("invalid state"),
141+
Err: SharedConfigProfileNotExistError{
142+
Filename: []string{filepath.Join("testdata", "shared_config_invalid_ini")},
143+
Profile: "profile_name",
144+
Err: nil,
146145
},
147146
},
148147
"S3UseARNRegion property on profile": {
@@ -687,16 +686,6 @@ func TestNewSharedConfig(t *testing.T) {
687686
EC2IMDSv1Disabled: aws.Bool(false),
688687
},
689688
},
690-
"leading whitespace error 1": {
691-
ConfigFilenames: []string{testConfigLeadingWSFilename1},
692-
Profile: "leading-whitespace-error",
693-
Err: fmt.Errorf("Invalid token, remove leading whitespace"),
694-
},
695-
"leading whitespace error 2": {
696-
ConfigFilenames: []string{testConfigLeadingWSFilename2},
697-
Profile: "leading-whitespace-error",
698-
Err: fmt.Errorf("Invalid token, remove leading whitespace"),
699-
},
700689
}
701690

702691
for name, c := range cases {

internal/ini/ast.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

internal/ini/bench_test.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

internal/ini/comma_token.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/ini/comment_token.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

internal/ini/dependency.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

internal/ini/doc.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

internal/ini/empty_token.go

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)