Skip to content

Commit

Permalink
fix(cfg): leverage opts in cfgs for aws
Browse files Browse the repository at this point in the history
Signed-off-by: Samantha Coyle <[email protected]>
  • Loading branch information
sicoyle committed Nov 13, 2024
1 parent 690b3ec commit a42e742
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bindings/aws/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (d *DynamoDB) Init(ctx context.Context, metadata bindings.Metadata) error {
SessionToken: meta.SessionToken,
}

provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/aws/kinesis/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (a *AWSKinesis) Init(ctx context.Context, metadata bindings.Metadata) error
SessionToken: "",
}
// extra configs needed per component type
provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/aws/ses/ses.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (a *AWSSES) Init(ctx context.Context, metadata bindings.Metadata) error {
SessionToken: "",
}
// extra configs needed per component type
provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions bindings/aws/sns/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"reflect"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sns"

"github.com/dapr/components-contrib/bindings"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (a *AWSSNS) Init(ctx context.Context, metadata bindings.Metadata) error {
SessionToken: m.SessionToken,
}
// extra configs needed per component type
provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/aws/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (a *AWSSQS) Init(ctx context.Context, metadata bindings.Metadata) error {
SessionToken: m.SessionToken,
}
// extra configs needed per component type
provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions common/authentication/aws/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ type StaticAuth struct {
}

func newStaticIAM(_ context.Context, opts Options, cfg *aws.Config) (*StaticAuth, error) {
if cfg == nil {
cfg = aws.NewConfig()
}
auth := &StaticAuth{
Logger: opts.Logger,
Region: opts.Region,
Endpoint: &opts.Endpoint,
AccessKey: &opts.AccessKey,
SecretKey: &opts.SecretKey,
SessionToken: &opts.SessionToken,
Cfg: cfg,
Clients: newClients(),
Cfg: func() *aws.Config {
// if nil is passed or it's just a default cfg,
// then we use the options to build the aws cfg.
if cfg != nil && cfg != aws.NewConfig() {
return cfg
}
return GetConfig(opts)
}(),
Clients: newClients(),
}

initialSession, err := auth.getTokenClient()
Expand Down
14 changes: 9 additions & 5 deletions common/authentication/aws/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,22 @@ func newX509(ctx context.Context, opts Options, cfg *aws.Config) (*x509, error)
return nil, errors.New("sessionDuration must be greater than 15 minutes, and less than 12 hours")
}

if cfg == nil {
cfg = aws.NewConfig()
}
auth := &x509{
wg: sync.WaitGroup{},
logger: opts.Logger,
TrustProfileArn: x509Auth.TrustProfileArn,
TrustAnchorArn: x509Auth.TrustAnchorArn,
AssumeRoleArn: x509Auth.AssumeRoleArn,
SessionDuration: x509Auth.SessionDuration,
Cfg: GetConfig(opts),
Clients: newClients(),
Cfg: func() *aws.Config {
// if nil is passed or it's just a default cfg,
// then we use the options to build the aws cfg.
if cfg != nil && cfg != aws.NewConfig() {
return cfg
}
return GetConfig(opts)
}(),
Clients: newClients(),
}

var err error
Expand Down
2 changes: 1 addition & 1 deletion pubsub/aws/snssqs/snssqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *snsSqs) Init(ctx context.Context, metadata pubsub.Metadata) error {
}
// extra configs needed per component type
var provider awsAuth.Provider
provider, err = awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err = awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion secretstores/aws/parameterstore/parameterstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *ssmSecretStore) Init(ctx context.Context, metadata secretstores.Metadat
SessionToken: "",
}
// extra configs needed per component type
provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions secretstores/aws/secretmanager/secretmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"reflect"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/secretsmanager"

awsAuth "github.com/dapr/components-contrib/common/authentication/aws"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (s *smSecretStore) Init(ctx context.Context, metadata secretstores.Metadata
Endpoint: meta.Endpoint,
}

provider, err := awsAuth.NewProvider(ctx, opts, aws.NewConfig())
provider, err := awsAuth.NewProvider(ctx, opts, awsAuth.GetConfig(opts))
if err != nil {
return err
}
Expand Down

0 comments on commit a42e742

Please sign in to comment.