From bd1388fb964d1df12975cd58cd45609d4458f884 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 29 Mar 2021 11:38:47 +0200 Subject: [PATCH] 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 --- internal/util/kms.go | 2 +- internal/util/util.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/util/kms.go b/internal/util/kms.go index bf9361a49..cd767e55c 100644 --- a/internal/util/kms.go +++ b/internal/util/kms.go @@ -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 diff --git a/internal/util/util.go b/internal/util/util.go index a907fd745..c4d2b6ece 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -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 +}