util: log available configs when KMS not found

When the KMS configuration can not be found, it is useful to know what
configurations are available. This aids troubleshooting when typos in
the KMS ID are made.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-03-29 11:38:47 +02:00 committed by mergify[bot]
parent a7c261a394
commit bd1388fb96
2 changed files with 15 additions and 1 deletions

View File

@ -67,7 +67,7 @@ func GetKMS(tenant, kmsID string, secrets map[string]string) (EncryptionKMS, err
section, ok := config[kmsID]
if !ok {
return nil, fmt.Errorf("could not get KMS configuration "+
"for %q", kmsID)
"for %q (have %v)", kmsID, getKeys(config))
}
// kmsConfig can have additional sub-sections

View File

@ -319,3 +319,17 @@ func contains(s []string, key string) bool {
return false
}
// getKeys takes a map that uses strings for keys and returns a slice with the
// keys.
func getKeys(m map[string]interface{}) []string {
keys := make([]string, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
return keys
}