From 6a1cf46cb0faa8455010bce92100ac7ce4d99d69 Mon Sep 17 00:00:00 2001 From: arivankar-px Date: Sun, 3 Sep 2023 21:21:35 +0530 Subject: [PATCH] Made changes based on review comments --- aws/aws_kms/aws_kms.go | 14 +------------- aws/aws_secrets_manager/aws_scm.go | 17 ++--------------- aws/credentials/credentials.go | 5 +++++ 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/aws/aws_kms/aws_kms.go b/aws/aws_kms/aws_kms.go index edcd629c..dd38ff4e 100644 --- a/aws/aws_kms/aws_kms.go +++ b/aws/aws_kms/aws_kms.go @@ -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" @@ -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, @@ -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 } diff --git a/aws/aws_secrets_manager/aws_scm.go b/aws/aws_secrets_manager/aws_scm.go index 5f4cb904..f2c6f80c 100644 --- a/aws/aws_secrets_manager/aws_scm.go +++ b/aws/aws_secrets_manager/aws_scm.go @@ -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" @@ -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, @@ -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) diff --git a/aws/credentials/credentials.go b/aws/credentials/credentials.go index eb0c0095..ddb6719d 100644 --- a/aws/credentials/credentials.go +++ b/aws/credentials/credentials.go @@ -14,6 +14,7 @@ import ( type AWSCredentials interface { Get() (*aws.Credentials, error) + GetCredentialsProvider() (aws.CredentialsProvider, error) } type awsCred struct { @@ -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 +}