Skip to content

Commit

Permalink
Merge pull request #219 from batchcorp/blinktag/aws_creds
Browse files Browse the repository at this point in the history
Support profiles for AWS credentials
  • Loading branch information
blinktag committed Jan 4, 2022
2 parents 48bafb2 + 45eb37a commit d32998a
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 187 deletions.
26 changes: 22 additions & 4 deletions backends/awskinesis/awskinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ func New(connOpts *opts.ConnectionOptions) (*Kinesis, error) {

connArgs := connOpts.GetAwsKinesis()

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
var sess *session.Session
var err error

if connArgs.AwsSecretAccessKey != "" {
sess, err = session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
} else {
// Use creds stored in ~/.aws/credentials
// https://github.com/batchcorp/plumber/issues/218
sess = session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
}

if err != nil {
return nil, errors.Wrap(err, "unable to initialize aws session")
}
Expand Down Expand Up @@ -82,6 +94,12 @@ func validateBaseConnOpts(connOpts *opts.ConnectionOptions) error {
return validate.ErrMissingConnArgs
}

// No need to go further, if profile is set, assume we don't need other args
// AWS SDK will pick up the profile creds from ~/.aws/credentials
if args.AwsProfile != "" {
return nil
}

if args.AwsSecretAccessKey == "" {
return validate.ErrMissingAWSSecretAccessKey
}
Expand Down
26 changes: 22 additions & 4 deletions backends/awssns/awssns.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,22 @@ func New(connOpts *opts.ConnectionOptions) (*AWSSNS, error) {

connArgs := connOpts.GetAwsSns()

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
var sess *session.Session
var err error

if connArgs.AwsSecretAccessKey != "" {
sess, err = session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
} else {
// Use creds stored in ~/.aws/credentials
// https://github.com/batchcorp/plumber/issues/218
sess = session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
}

if err != nil {
return nil, errors.Wrap(err, "unable to initialize aws session")
}
Expand Down Expand Up @@ -85,6 +97,12 @@ func validateBaseConnOpts(connOpts *opts.ConnectionOptions) error {
return validate.ErrMissingConnArgs
}

// No need to go further, if profile is set, assume we don't need other args
// AWS SDK will pick up the profile creds from ~/.aws/credentials
if args.AwsProfile != "" {
return nil
}

if args.AwsSecretAccessKey == "" {
return validate.ErrMissingAWSSecretAccessKey
}
Expand Down
27 changes: 23 additions & 4 deletions backends/awssqs/awssqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
Expand Down Expand Up @@ -44,10 +45,22 @@ func New(connOpts *opts.ConnectionOptions) (*AWSSQS, error) {

connArgs := connOpts.GetAwsSqs()

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
var sess *session.Session
var err error

if connArgs.AwsSecretAccessKey != "" {
sess, err = session.NewSession(&aws.Config{
Region: aws.String(connArgs.AwsRegion),
Credentials: credentials.NewStaticCredentials(connArgs.AwsAccessKeyId, connArgs.AwsSecretAccessKey, ""),
})
} else {
// Use creds stored in ~/.aws/credentials
// https://github.com/batchcorp/plumber/issues/218
sess = session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
}

if err != nil {
return nil, errors.Wrap(err, "unable to initialize aws session")
}
Expand Down Expand Up @@ -90,6 +103,12 @@ func validateBaseConnOpts(connOpts *opts.ConnectionOptions) error {
return validate.ErrMissingConnArgs
}

// No need to go further, if profile is set, assume we don't need other args
// AWS SDK will pick up the profile creds from ~/.aws/credentials
if args.AwsProfile != "" {
return nil
}

if args.AwsSecretAccessKey == "" {
return validate.ErrMissingAWSSecretAccessKey
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/batchcorp/collector-schemas v0.0.5
github.com/batchcorp/kong v0.2.17-batch-fix
github.com/batchcorp/pgoutput v0.3.2
github.com/batchcorp/plumber-schemas v0.0.122
github.com/batchcorp/plumber-schemas v0.0.123
github.com/batchcorp/rabbit v0.1.17
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/fatih/color v1.12.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ github.com/batchcorp/plumber-schemas v0.0.121 h1:nxdlIk18BPrloSpcu6NXibPw+zb3VHa
github.com/batchcorp/plumber-schemas v0.0.121/go.mod h1:YULMKnfZ8X7tglTfUzKXhWc1Bfq6dy5ysIQbvsbCOkY=
github.com/batchcorp/plumber-schemas v0.0.122 h1:oC8QJtie6b7SAegBWt1xDllCj87gNXoJ0a8rC3tJyWI=
github.com/batchcorp/plumber-schemas v0.0.122/go.mod h1:YULMKnfZ8X7tglTfUzKXhWc1Bfq6dy5ysIQbvsbCOkY=
github.com/batchcorp/plumber-schemas v0.0.123 h1:5/cq83sHWPZeO2QBlSSmWSmIe6RE6nDwV8E3Obu8RrY=
github.com/batchcorp/plumber-schemas v0.0.123/go.mod h1:YULMKnfZ8X7tglTfUzKXhWc1Bfq6dy5ysIQbvsbCOkY=
github.com/batchcorp/rabbit v0.1.9 h1:BzQStzeo0WuvC7+PKYaEBYtn9qqramlaZCN1CxmNM6U=
github.com/batchcorp/rabbit v0.1.9/go.mod h1:LaAQ6FCNkir0/SbJ9jX3JNNP1ULAU2M3QZN/IwFRwXw=
github.com/batchcorp/rabbit v0.1.16 h1:TqyToURClYCPNiBzMOF0Cj87X1i9vLLZn0nG8PzawcE=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d32998a

Please sign in to comment.