diff --git a/pkg/mapper/configmap/configmap.go b/pkg/mapper/configmap/configmap.go index fa40be7fa..70aad0cb9 100644 --- a/pkg/mapper/configmap/configmap.go +++ b/pkg/mapper/configmap/configmap.go @@ -117,25 +117,31 @@ func ParseMap(m map[string]string) (userMappings []config.UserMapping, roleMappi errs := make([]error, 0) userMappings = make([]config.UserMapping, 0) if userData, ok := m["mapUsers"]; ok { - err := yaml.Unmarshal([]byte(userData), &userMappings) - if err != nil { - errs = append(errs, err) + if !isSkippable(userData) { + err := yaml.Unmarshal([]byte(userData), &userMappings) + if err != nil { + errs = append(errs, err) + } } } roleMappings = make([]config.RoleMapping, 0) if roleData, ok := m["mapRoles"]; ok { - err := yaml.Unmarshal([]byte(roleData), &roleMappings) - if err != nil { - errs = append(errs, err) + if !isSkippable(roleData) { + err := yaml.Unmarshal([]byte(roleData), &roleMappings) + if err != nil { + errs = append(errs, err) + } } } awsAccounts = make([]string, 0) if accountsData, ok := m["mapAccounts"]; ok { - err := yaml.Unmarshal([]byte(accountsData), &awsAccounts) - if err != nil { - errs = append(errs, err) + if !isSkippable(accountsData) { + err := yaml.Unmarshal([]byte(accountsData), &awsAccounts) + if err != nil { + errs = append(errs, err) + } } } @@ -146,6 +152,11 @@ func ParseMap(m map[string]string) (userMappings []config.UserMapping, roleMappi return userMappings, roleMappings, awsAccounts, err } +func isSkippable(data string) bool { + trimmed := strings.TrimSpace(data) + return trimmed == "" || trimmed == "``" || trimmed == "\"\"" +} + func EncodeMap(userMappings []config.UserMapping, roleMappings []config.RoleMapping, awsAccounts []string) (m map[string]string, err error) { m = make(map[string]string) diff --git a/pkg/mapper/configmap/configmap_test.go b/pkg/mapper/configmap/configmap_test.go index 6ae3dac10..d6692d066 100644 --- a/pkg/mapper/configmap/configmap_test.go +++ b/pkg/mapper/configmap/configmap_test.go @@ -285,3 +285,25 @@ func TestParseMap(t *testing.T) { t.Fatalf("unexpected %v != %v", m1, m2) } } + +func TestBadParseMap(t *testing.T) { + m1 := map[string]string{ + "mapAccounts": ``, + "mapRoles": `""`, + "mapUsers": "``", + } + + u, r, a, err := ParseMap(m1) + if err != nil { + t.Fatal(err) + } + + m2, err := EncodeMap(u, r, a) + if err != nil { + t.Fatal(err) + } + emptyMap := map[string]string{} + if !reflect.DeepEqual(emptyMap, m2) { + t.Fatalf("unexpected %v != %v", emptyMap, m2) + } +}