Skip to content

Commit

Permalink
fix: translation of ini service sections into shared config
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Dec 7, 2023
1 parent 0d643a8 commit be83300
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
9 changes: 9 additions & 0 deletions .changelog/f2db4c5b72b448adb7049b56df9e29eb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "f2db4c5b-72b4-48ad-b704-9b56df9e29eb",
"type": "bugfix",
"description": "Correct loading of [services *] sections into shared config.",
"modules": [
"config",
"internal/ini"
]
}
24 changes: 13 additions & 11 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

// Prefix for services section. It is referenced in profile via the services
// parameter to configure clients for service-specific parameters.
servicesPrefix = `services`
servicesPrefix = `services `

// string equivalent for boolean
endpointDiscoveryDisabled = `false`
Expand Down Expand Up @@ -109,6 +109,8 @@ const (

endpointURL = "endpoint_url"

servicesSectionKey = "services"

disableRequestCompression = "disable_request_compression"
requestMinCompressionSizeBytes = "request_min_compression_size_bytes"

Expand Down Expand Up @@ -320,8 +322,9 @@ type SharedConfig struct {
// corresponding endpoint resolution field.
BaseEndpoint string

// Value to contain services section content.
Services Services
// Services section config.
ServicesSectionName string
Services Services

// determine if request compression is allowed, default to false
// retrieved from config file's profile field disable_request_compression
Expand Down Expand Up @@ -1007,14 +1010,11 @@ func (c *SharedConfig) setFromIniSections(profiles map[string]struct{}, profile
c.SSOSession = &ssoSession
}

for _, sectionName := range sections.List() {
if strings.HasPrefix(sectionName, servicesPrefix) {
section, ok := sections.GetSection(sectionName)
if ok {
var svcs Services
svcs.setFromIniSection(section)
c.Services = svcs
}
if len(c.ServicesSectionName) > 0 {
if section, ok := sections.GetSection(servicesPrefix + c.ServicesSectionName); ok {
var svcs Services
svcs.setFromIniSection(section)
c.Services = svcs
}
}

Expand Down Expand Up @@ -1136,6 +1136,8 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
c.Credentials = creds
}

updateString(&c.ServicesSectionName, section, servicesSectionKey)

return nil
}

Expand Down
19 changes: 19 additions & 0 deletions config/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,25 @@ func TestNewSharedConfig(t *testing.T) {
Profile: "request_compression_min_request_out_of_bounds",
Err: fmt.Errorf("invalid range for min request compression size bytes 10485761, must be within 0 and 10485760 inclusively"),
},
"services section": {
ConfigFilenames: []string{testConfigFilename},
Profile: "service_endpoint_url",
Expected: SharedConfig{
Profile: "service_endpoint_url",
ServicesSectionName: "service_endpoint_url_services",
Services: Services{
ServiceValues: map[string]map[string]string{
"s3": map[string]string{
"endpoint_url": "http://127.0.0.1",
"other": "foo",
},
"ec2": map[string]string{
"endpoint_url": "http://127.0.0.1:81",
},
},
},
},
},
}

for name, c := range cases {
Expand Down
10 changes: 10 additions & 0 deletions config/testdata/shared_config
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,13 @@ request_min_compression_size_bytes = hahaha
[profile request_compression_min_request_out_of_bounds]
disable_request_compression = false
request_min_compression_size_bytes = 10485761

[profile service_endpoint_url]
services = service_endpoint_url_services

[services service_endpoint_url_services]
s3 =
endpoint_url = http://127.0.0.1
other = foo
ec2 =
endpoint_url = http://127.0.0.1:81
13 changes: 1 addition & 12 deletions internal/ini/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,7 @@ func (v Value) String() string {

// MapValue returns a map value for sub properties
func (v Value) MapValue() map[string]string {
newlineParts := strings.Split(string(v.str), "\n")
mp := make(map[string]string)
for _, part := range newlineParts {
operandParts := strings.Split(part, "=")
if len(operandParts) < 2 {
continue
}
key := strings.TrimSpace(operandParts[0])
val := strings.TrimSpace(operandParts[1])
mp[key] = val
}
return mp
return v.mp
}

// IntValue returns an integer value
Expand Down

0 comments on commit be83300

Please sign in to comment.