diff --git a/.changelog/f2db4c5b72b448adb7049b56df9e29eb.json b/.changelog/f2db4c5b72b448adb7049b56df9e29eb.json new file mode 100644 index 00000000000..72ca5ec7b37 --- /dev/null +++ b/.changelog/f2db4c5b72b448adb7049b56df9e29eb.json @@ -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" + ] +} \ No newline at end of file diff --git a/config/shared_config.go b/config/shared_config.go index 422dfc55bea..c546cb7d0f5 100644 --- a/config/shared_config.go +++ b/config/shared_config.go @@ -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` @@ -109,6 +109,8 @@ const ( endpointURL = "endpoint_url" + servicesSectionKey = "services" + disableRequestCompression = "disable_request_compression" requestMinCompressionSizeBytes = "request_min_compression_size_bytes" @@ -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 @@ -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 } } @@ -1136,6 +1136,8 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er c.Credentials = creds } + updateString(&c.ServicesSectionName, section, servicesSectionKey) + return nil } diff --git a/config/shared_config_test.go b/config/shared_config_test.go index b99fb0c2470..d448f50b2b7 100644 --- a/config/shared_config_test.go +++ b/config/shared_config_test.go @@ -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 { diff --git a/config/testdata/shared_config b/config/testdata/shared_config index 96122cf242f..ba5f80644e5 100644 --- a/config/testdata/shared_config +++ b/config/testdata/shared_config @@ -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 diff --git a/internal/ini/value.go b/internal/ini/value.go index ade75bf34e4..e3706b3c31b 100644 --- a/internal/ini/value.go +++ b/internal/ini/value.go @@ -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