Skip to content

Commit

Permalink
Keep consistent behavior with boolean handling in shared config
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Nov 3, 2021
1 parent b185db9 commit a1cf4d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
30 changes: 8 additions & 22 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,8 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
}
updateString(&c.EC2IMDSEndpoint, section, ec2MetadataServiceEndpointKey)

if err := updateUseDualStackEndpoint(&c.UseDualStackEndpoint, section, useDualStackEndpoint); err != nil {
return fmt.Errorf("failed to load %s from shared config, %v", useDualStackEndpoint, err)
}
if err := updateUseFIPSEndpoint(&c.UseFIPSEndpoint, section, useFIPSEndpointKey); err != nil {
return fmt.Errorf("failed to load %s from shared config, %v", useFIPSEndpointKey, err)
}
updateUseDualStackEndpoint(&c.UseDualStackEndpoint, section, useDualStackEndpoint)
updateUseFIPSEndpoint(&c.UseFIPSEndpoint, section, useFIPSEndpointKey)

// Shared Credentials
creds := aws.Credentials{
Expand Down Expand Up @@ -1283,14 +1279,9 @@ func updateEndpointDiscoveryType(dst *aws.EndpointDiscoveryEnableState, section

// updateEndpointDiscoveryType will only update the dst with the value in the section, if
// a valid key and corresponding EndpointDiscoveryType is found.
func updateUseDualStackEndpoint(dst *aws.DualStackEndpointState, section ini.Section, key string) error {
func updateUseDualStackEndpoint(dst *aws.DualStackEndpointState, section ini.Section, key string) {
if !section.Has(key) {
return nil
}

valueType, _ := section.ValueType(key)
if valueType != ini.BoolType {
return fmt.Errorf("expected true or false, got %v", section.String(key))
return
}

if section.Bool(key) {
Expand All @@ -1299,19 +1290,14 @@ func updateUseDualStackEndpoint(dst *aws.DualStackEndpointState, section ini.Sec
*dst = aws.DualStackEndpointStateDisabled
}

return nil
return
}

// updateEndpointDiscoveryType will only update the dst with the value in the section, if
// a valid key and corresponding EndpointDiscoveryType is found.
func updateUseFIPSEndpoint(dst *aws.FIPSEndpointState, section ini.Section, key string) error {
func updateUseFIPSEndpoint(dst *aws.FIPSEndpointState, section ini.Section, key string) {
if !section.Has(key) {
return nil
}

valueType, _ := section.ValueType(key)
if valueType != ini.BoolType {
return fmt.Errorf("expected true or false, got %v", section.String(key))
return
}

if section.Bool(key) {
Expand All @@ -1320,5 +1306,5 @@ func updateUseFIPSEndpoint(dst *aws.FIPSEndpointState, section ini.Section, key
*dst = aws.FIPSEndpointStateDisabled
}

return nil
return
}
12 changes: 10 additions & 2 deletions config/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ func TestNewSharedConfig(t *testing.T) {
ConfigFilenames: []string{testConfigFilename},
CredentialsFilenames: []string{testCredentialsFilename},
Profile: "UseDualStackEndpointInvalid",
Err: fmt.Errorf("failed to load use_dualstack_endpoint from shared config, expected true or false, got invalid"),
Expected: SharedConfig{
Profile: "UseDualStackEndpointInvalid",
Region: "us-west-2",
UseDualStackEndpoint: aws.DualStackEndpointStateDisabled,
},
},
"fips endpoint enabled": {
ConfigFilenames: []string{testConfigFilename},
Expand All @@ -500,7 +504,11 @@ func TestNewSharedConfig(t *testing.T) {
ConfigFilenames: []string{testConfigFilename},
CredentialsFilenames: []string{testCredentialsFilename},
Profile: "UseFIPSEndpointInvalid",
Err: fmt.Errorf("failed to load use_fips_endpoint from shared config, expected true or false, got invalid"),
Expected: SharedConfig{
Profile: "UseFIPSEndpointInvalid",
Region: "us-west-2",
UseFIPSEndpoint: aws.FIPSEndpointStateDisabled,
},
},
}

Expand Down

0 comments on commit a1cf4d8

Please sign in to comment.