Skip to content

Commit

Permalink
feat: support KMS with prefixed store namespace
Browse files Browse the repository at this point in the history
This change allows a local KMS instance to be created with a prefixed store namespace

closes hyperledger-archives#2435

Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Jan 22, 2021
1 parent 3510620 commit 2935f30
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/kms/localkms/localkms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 2935f30

Please sign in to comment.