Skip to content

Commit

Permalink
Merge pull request #276 from exosite/master
Browse files Browse the repository at this point in the history
Add --role-arn support
  • Loading branch information
barnybug authored Oct 29, 2019
2 parents f1b23d1 + 1621c37 commit 13038ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ You can switch between different sets in the credentials file by passing

cli53 list --profile my_profile

You can also assume a specific role by passing `--role-arn` to any command.
For example:

cli53 list --role-arn arn:aws:iam::123456789012:role/myRole

You can combine role with profile.
For example:

cli53 list --profile my_profile --role-arn arn:aws:iam::123456789012:role/myRole

For more information, see: http://blogs.aws.amazon.com/security/post/Tx3D6U6WSFGOK2H/A-New-and-Standardized-Way-to-Manage-Credentials-in-the-AWS-SDKs

Note: for Alpine on Docker, the pre-built binaries do not work, so either use Debian, or follow the instructions below for Building from source.
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func Main(args []string) int {
Name: "profile",
Usage: "profile to use from credentials file",
},
cli.StringFlag{
Name: "role-arn",
Usage: "AWS role ARN to assume",
},
cli.StringFlag{
Name: "endpoint-url",
Usage: "override Route53 endpoint (hostname or fully qualified URI)",
Expand Down
9 changes: 9 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)
Expand Down Expand Up @@ -70,6 +71,14 @@ func getService(c *cli.Context) (*route53.Route53, error) {
if err != nil {
return nil, err
}
roleARN := c.String("role-arn")
if roleARN != "" {
roleCreds := stscreds.NewCredentials(sess, roleARN)
if err != nil {
return nil, err
}
config.Credentials = roleCreds
}
return route53.New(sess, config), nil
}

Expand Down

0 comments on commit 13038ed

Please sign in to comment.