From 8be3cd5a72a122e7d5c0200164e72838b3fdbbab Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Wed, 9 Mar 2022 13:49:17 -0300 Subject: [PATCH] Moving duplication validation logic to utils method Signed-off-by: Gustavo Carvalho --- pkg/provider/vault/vault.go | 6 ------ pkg/utils/utils.go | 6 +++++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/provider/vault/vault.go b/pkg/provider/vault/vault.go index ca492185d..8609891b0 100644 --- a/pkg/provider/vault/vault.go +++ b/pkg/provider/vault/vault.go @@ -276,9 +276,6 @@ func (v *client) findSecretsFromTags(ctx context.Context, candidates []string, t if removeFromName != "" { name = strings.TrimPrefix(name, removeFromName) } - if _, exists := secrets[name]; exists { - return nil, fmt.Errorf(errDuplicateSecret, name) - } secrets[name] = secret } } @@ -300,9 +297,6 @@ func (v *client) findSecretsFromName(ctx context.Context, candidates []string, r if removeFromName != "" { name = strings.TrimPrefix(name, removeFromName) } - if _, exists := secrets[name]; exists { - return nil, fmt.Errorf(errDuplicateSecret, name) - } secrets[name] = secret } } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 6bb8fc2b8..9dba79d21 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -60,7 +60,11 @@ func ConvertKeys(strategy esv1beta1.ExternalSecretConversionStrategy, in map[str newName[rk] = string(rv) } } - out[strings.Join(newName, "")] = v + key := strings.Join(newName, "") + if _, exists := out[key]; exists { + return nil, fmt.Errorf("secret name collision during conversion: %s", key) + } + out[key] = v } return out, nil }