From 2935f308b5036162a45a7be6e0215eb067092779 Mon Sep 17 00:00:00 2001 From: Baha Shaaban Date: Fri, 22 Jan 2021 17:46:33 -0500 Subject: [PATCH] feat: support KMS with prefixed store namespace This change allows a local KMS instance to be created with a prefixed store namespace closes #2435 Signed-off-by: Baha Shaaban --- pkg/kms/localkms/localkms.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/kms/localkms/localkms.go b/pkg/kms/localkms/localkms.go index b1af52191..cb747985a 100644 --- a/pkg/kms/localkms/localkms.go +++ b/pkg/kms/localkms/localkms.go @@ -55,8 +55,8 @@ type LocalKMS struct { primaryKeyEnvAEAD *aead.KMSEnvelopeAEAD } -func newKeyIDWrapperStore(provider storage.Provider) (storage.Store, error) { - s, err := provider.OpenStore(Namespace) +func newKeyIDWrapperStore(provider storage.Provider, storePrefix string) (storage.Store, error) { + s, err := provider.OpenStore(storePrefix + Namespace) if err != nil { return nil, err } @@ -66,7 +66,12 @@ func newKeyIDWrapperStore(provider storage.Provider) (storage.Store, error) { // New will create a new (local) KMS service. func New(primaryKeyURI string, p kms.Provider) (*LocalKMS, error) { - store, err := newKeyIDWrapperStore(p.StorageProvider()) + return NewWithPrefix(primaryKeyURI, p, "") +} + +// NewWithPrefix will create a new (local) KMS service using a store name prefixed with storePrefix. +func NewWithPrefix(primaryKeyURI string, p kms.Provider, storePrefix string) (*LocalKMS, error) { + store, err := newKeyIDWrapperStore(p.StorageProvider(), storePrefix) if err != nil { return nil, fmt.Errorf("new: failed to ceate local kms: %w", err) }