Skip to content

Commit

Permalink
Made changes based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arivankar-px committed Sep 3, 2023
1 parent 4c53935 commit 6a1cf46
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
14 changes: 1 addition & 13 deletions aws/aws_kms/aws_kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/libopenstorage/secrets/aws/utils"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/kms"
"github.com/aws/aws-sdk-go-v2/service/kms/types"
"github.com/libopenstorage/secrets"
Expand Down Expand Up @@ -85,7 +84,7 @@ func New(
if err != nil {
return nil, fmt.Errorf("Failed to get credentials: %v", err)
}
credProv := credentialsToProvider(creds)
credProv, err := asc.GetCredentialsProvider()
config := aws.Config{
Credentials: credProv,
Region: region,
Expand All @@ -102,17 +101,6 @@ func New(
}, nil
}

func credentialsToProvider(creds *aws.Credentials) aws.CredentialsProvider {
return credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: creds.AccessKeyID,
SecretAccessKey: creds.SecretAccessKey,
SessionToken: creds.SessionToken,
Source: creds.Source,
},
}
}

func (a *awsKmsSecrets) String() string {
return Name
}
Expand Down
17 changes: 2 additions & 15 deletions aws/aws_secrets_manager/aws_scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager/types"
"github.com/libopenstorage/secrets"
Expand Down Expand Up @@ -64,11 +63,11 @@ func New(
if err != nil {
return nil, fmt.Errorf("failed to create aws credentials instance: %v", err)
}
creds, err := asc.Get()
_, err = asc.Get()
if err != nil {
return nil, fmt.Errorf("failed to get credentials: %v", err)
}
credProv := CredentialsToProvider(creds)
credProv, err := asc.GetCredentialsProvider()
config := aws.Config{
Credentials: credProv,
Region: region,
Expand All @@ -77,18 +76,6 @@ func New(
return NewFromAWSConfig(config)
}

// credentialsToProvider converts a aws.Credential object to a aws.CredentialProvider object
func CredentialsToProvider(creds *aws.Credentials) aws.CredentialsProvider {
return credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: creds.AccessKeyID,
SecretAccessKey: creds.SecretAccessKey,
SessionToken: creds.SessionToken,
Source: creds.Source,
},
}
}

// NewFromAWSConfig creates new instance of AWSSecretsMgr with provided AWS configuration (aws.Config).
func NewFromAWSConfig(config aws.Config) (*AWSSecretsMgr, error) {
scm := secretsmanager.NewFromConfig(config)
Expand Down
5 changes: 5 additions & 0 deletions aws/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

type AWSCredentials interface {
Get() (*aws.Credentials, error)
GetCredentialsProvider() (aws.CredentialsProvider, error)
}

type awsCred struct {
Expand Down Expand Up @@ -68,3 +69,7 @@ func (a *awsCred) Get() (*aws.Credentials, error) {
}
return a.creds, nil
}

func (a *awsCred) GetCredentialsProvider() (aws.CredentialsProvider, error) {
return a.credsprovider, nil
}

0 comments on commit 6a1cf46

Please sign in to comment.