Skip to content

Commit

Permalink
Merge pull request #783 from ChaitanyaSingla/remove-dynamodb-required…
Browse files Browse the repository at this point in the history
…-fields

Changes related to DynamoDB credentials usage
  • Loading branch information
denopink authored Sep 23, 2024
2 parents 14ee53a + 8f35e88 commit 4d2e306
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions store/dynamodb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ type Config struct {
GetAllLimit int

// AccessKey is the AWS AccessKey credential.
AccessKey string `validate:"required"`
AccessKey string

// SecretKey is the AWS SecretKey credential.
SecretKey string `validate:"required"`
SecretKey string

// DisableDualStack indicates whether the connection to the DB should be
// dual stack (IPv4 and IPv6).
Expand Down Expand Up @@ -96,6 +96,7 @@ func NewDynamoDB(config Config, measures metric.Measures) (store.S, error) {
}

var creds credentials.Value
var awsConfig aws.Config
if config.RoleBasedAccess {
awsRegion, err := getAwsRegionForRoleBasedAccess(config)
if err != nil {
Expand All @@ -109,30 +110,27 @@ func NewDynamoDB(config Config, measures metric.Measures) (store.S, error) {
return nil, err
}

value, err := sess.Config.Credentials.Get()
if err != nil {
return nil, err
}

creds = credentials.Value{
AccessKeyID: value.AccessKeyID,
SecretAccessKey: value.SecretAccessKey,
SessionToken: value.SessionToken,
}
awsConfig = *aws.NewConfig().
WithEndpoint(config.Endpoint).
WithUseDualStack(!config.DisableDualStack).
WithMaxRetries(config.MaxRetries).
WithCredentialsChainVerboseErrors(true).
WithRegion(config.Region).
WithCredentials(sess.Config.Credentials)
} else {
creds = credentials.Value{
AccessKeyID: config.AccessKey,
SecretAccessKey: config.SecretKey,
}
}

awsConfig := *aws.NewConfig().
WithEndpoint(config.Endpoint).
WithUseDualStack(!config.DisableDualStack).
WithMaxRetries(config.MaxRetries).
WithCredentialsChainVerboseErrors(true).
WithRegion(config.Region).
WithCredentials(credentials.NewStaticCredentialsFromCreds(creds))
awsConfig = *aws.NewConfig().
WithEndpoint(config.Endpoint).
WithUseDualStack(!config.DisableDualStack).
WithMaxRetries(config.MaxRetries).
WithCredentialsChainVerboseErrors(true).
WithRegion(config.Region).
WithCredentials(credentials.NewStaticCredentialsFromCreds(creds))
}

svc, err := newService(awsConfig, "", config.Table, int64(config.GetAllLimit), &measures)
if err != nil {
Expand Down

0 comments on commit 4d2e306

Please sign in to comment.