Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
changes as per review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Rajesh Kalaria <[email protected]>
  • Loading branch information
rajeshkalaria80 committed Dec 5, 2022
1 parent 0084947 commit 6ba8651
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 107 deletions.
17 changes: 14 additions & 3 deletions pkg/aws/opts.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package aws

import (
envutil "github.com/trustbloc/kms/pkg/env"
"os"
)

type opts struct {
keyAliasPrefix string
}

func NewOpts() *opts {
// NewOpts create new opts populated with environment variable.
func newOpts() *opts {
value, _ := os.LookupEnv("AWS_KEY_ALIAS_PREFIX")

return &opts{
keyAliasPrefix: envutil.StringEnvOpt("AWS_KEY_ALIAS_PREFIX", ""),
keyAliasPrefix: value,
}
}

func (o *opts) KeyAliasPrefix() string {
return o.keyAliasPrefix
}

// Opts a Functional Options.
type Opts func(opts *opts)

// WithKeyAliasPrefix sets the given prefix in the returns Opts.
func WithKeyAliasPrefix(prefix string) Opts {
return func(opts *opts) { opts.keyAliasPrefix = prefix }
}
15 changes: 9 additions & 6 deletions pkg/aws/opts_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//go:build unit
// +build unit
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
package aws
SPDX-License-Identifier: Apache-2.0
*/

package aws //nolint:testpackage

import (
"testing"
Expand All @@ -11,13 +14,13 @@ import (

func TestOpts(t *testing.T) {
t.Run("options: defaults", func(t *testing.T) {
options := NewOpts()
options := newOpts()

require.Equal(t, "", options.KeyAliasPrefix())
})

t.Run("options: set manually", func(t *testing.T) {
options := NewOpts()
options := newOpts()

WithKeyAliasPrefix("keyaliasprefix")(options)

Expand All @@ -27,7 +30,7 @@ func TestOpts(t *testing.T) {
t.Run("options: env vars", func(t *testing.T) {
t.Setenv("AWS_KEY_ALIAS_PREFIX", "keyaliasprefix")

options := NewOpts()
options := newOpts()

require.Equal(t, "keyaliasprefix", options.KeyAliasPrefix())
})
Expand Down
3 changes: 1 addition & 2 deletions pkg/aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var keySpecToCurve = map[string]elliptic.Curve{

// New return aws service.
func New(awsSession *session.Session, metrics metricsProvider, healthCheckKeyID string, opts ...Opts) *Service {
options := NewOpts()
options := newOpts()

for _, opt := range opts {
opt(options)
Expand Down Expand Up @@ -242,7 +242,6 @@ func (s *Service) Create(kt arieskms.KeyType) (string, interface{}, error) {
if err != nil {
return "", nil, err
}

}

return *result.KeyMetadata.KeyId, *result.KeyMetadata.KeyId, nil
Expand Down
37 changes: 0 additions & 37 deletions pkg/env/util.go

This file was deleted.

59 changes: 0 additions & 59 deletions pkg/env/util_test.go

This file was deleted.

0 comments on commit 6ba8651

Please sign in to comment.