github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/euaccess/whitelisted_globalaccounts.go (about) 1 package euaccess 2 3 import ( 4 "fmt" 5 "os" 6 7 "gopkg.in/yaml.v2" 8 ) 9 10 const ( 11 WhitelistKey = "whitelist" 12 ) 13 14 type WhitelistSet map[string]struct{} 15 16 func IsNotWhitelisted(globalAccountId string, whitelist WhitelistSet) bool { 17 _, found := whitelist[globalAccountId] 18 return !found 19 } 20 21 func ReadWhitelistedGlobalAccountIdsFromFile(filename string) (WhitelistSet, error) { 22 yamlData := make(map[string][]string) 23 whitelistSet := WhitelistSet{} 24 var whitelist, err = os.ReadFile(filename) 25 if err != nil { 26 return whitelistSet, fmt.Errorf("while reading %s file with whitelisted GlobalAccountIds config: %w", filename, err) 27 } 28 err = yaml.Unmarshal(whitelist, &yamlData) 29 if err != nil { 30 return whitelistSet, fmt.Errorf("while unmarshalling a file with whitelisted GlobalAccountIds config: %w", err) 31 } 32 for _, id := range yamlData[WhitelistKey] { 33 whitelistSet[id] = struct{}{} 34 } 35 return whitelistSet, nil 36 }