Skip to content

Commit c5c34b3

Browse files
authored
fix: translation of ini service sections into shared config (#2416)
1 parent b3c7fbf commit c5c34b3

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "f2db4c5b-72b4-48ad-b704-9b56df9e29eb",
3+
"type": "bugfix",
4+
"description": "Correct loading of [services *] sections into shared config.",
5+
"modules": [
6+
"config",
7+
"internal/ini"
8+
]
9+
}

config/shared_config.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131

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

3636
// string equivalent for boolean
3737
endpointDiscoveryDisabled = `false`
@@ -109,6 +109,8 @@ const (
109109

110110
endpointURL = "endpoint_url"
111111

112+
servicesSectionKey = "services"
113+
112114
disableRequestCompression = "disable_request_compression"
113115
requestMinCompressionSizeBytes = "request_min_compression_size_bytes"
114116

@@ -320,8 +322,9 @@ type SharedConfig struct {
320322
// corresponding endpoint resolution field.
321323
BaseEndpoint string
322324

323-
// Value to contain services section content.
324-
Services Services
325+
// Services section config.
326+
ServicesSectionName string
327+
Services Services
325328

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

1010-
for _, sectionName := range sections.List() {
1011-
if strings.HasPrefix(sectionName, servicesPrefix) {
1012-
section, ok := sections.GetSection(sectionName)
1013-
if ok {
1014-
var svcs Services
1015-
svcs.setFromIniSection(section)
1016-
c.Services = svcs
1017-
}
1013+
if len(c.ServicesSectionName) > 0 {
1014+
if section, ok := sections.GetSection(servicesPrefix + c.ServicesSectionName); ok {
1015+
var svcs Services
1016+
svcs.setFromIniSection(section)
1017+
c.Services = svcs
10181018
}
10191019
}
10201020

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

1139+
updateString(&c.ServicesSectionName, section, servicesSectionKey)
1140+
11391141
return nil
11401142
}
11411143

config/shared_config_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,25 @@ func TestNewSharedConfig(t *testing.T) {
711711
Profile: "request_compression_min_request_out_of_bounds",
712712
Err: fmt.Errorf("invalid range for min request compression size bytes 10485761, must be within 0 and 10485760 inclusively"),
713713
},
714+
"services section": {
715+
ConfigFilenames: []string{testConfigFilename},
716+
Profile: "service_endpoint_url",
717+
Expected: SharedConfig{
718+
Profile: "service_endpoint_url",
719+
ServicesSectionName: "service_endpoint_url_services",
720+
Services: Services{
721+
ServiceValues: map[string]map[string]string{
722+
"s3": map[string]string{
723+
"endpoint_url": "http://127.0.0.1",
724+
"other": "foo",
725+
},
726+
"ec2": map[string]string{
727+
"endpoint_url": "http://127.0.0.1:81",
728+
},
729+
},
730+
},
731+
},
732+
},
714733
}
715734

716735
for name, c := range cases {

config/testdata/shared_config

+10
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,13 @@ request_min_compression_size_bytes = hahaha
307307
[profile request_compression_min_request_out_of_bounds]
308308
disable_request_compression = false
309309
request_min_compression_size_bytes = 10485761
310+
311+
[profile service_endpoint_url]
312+
services = service_endpoint_url_services
313+
314+
[services service_endpoint_url_services]
315+
s3 =
316+
endpoint_url = http://127.0.0.1
317+
other = foo
318+
ec2 =
319+
endpoint_url = http://127.0.0.1:81

internal/ini/value.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,7 @@ func (v Value) String() string {
5454

5555
// MapValue returns a map value for sub properties
5656
func (v Value) MapValue() map[string]string {
57-
newlineParts := strings.Split(string(v.str), "\n")
58-
mp := make(map[string]string)
59-
for _, part := range newlineParts {
60-
operandParts := strings.Split(part, "=")
61-
if len(operandParts) < 2 {
62-
continue
63-
}
64-
key := strings.TrimSpace(operandParts[0])
65-
val := strings.TrimSpace(operandParts[1])
66-
mp[key] = val
67-
}
68-
return mp
57+
return v.mp
6958
}
7059

7160
// IntValue returns an integer value

0 commit comments

Comments
 (0)