Skip to content

Commit

Permalink
add read AWS credentials read from args.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Feb 25, 2018
1 parent b0bd9ab commit 61c7350
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
35 changes: 33 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,41 @@ package main
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/urfave/cli"
)

func awsConfig() (aws.Config, error) {
cfg, err := external.LoadDefaultAWSConfig()
func awsConfigArgs(c *cli.Context) (string, string, string, string, string) {
return c.String("aws-access-key-id"),
c.String("aws-secret-access-key"),
c.String("aws-session-token"),
c.String("profile"),
c.String("aws-region")
}

func awsConfig(keyid, secretid, token, profile, region string) (aws.Config, error) {
configs := make([]external.Config, 0)

if keyid != "" && secretid != "" {
credentials := aws.Credentials{
AccessKeyID: keyid,
SecretAccessKey: secretid,
}
configs = append(configs, external.WithCredentialsValue(credentials))
} else if token != "" {
credentials := aws.Credentials{
SessionToken: token,
}
configs = append(configs, external.WithCredentialsValue(credentials))
}
if profile != "" {
configs = append(configs, external.WithSharedConfigProfile(profile))
}

if region != "" {
configs = append(configs, external.WithRegion(region))
}

cfg, err := external.LoadDefaultAWSConfig(configs...)
if err != nil {
return aws.Config{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func runGet(c *cli.Context) error {
group := c.Args().Get(0)
streamPrefix := c.Args().Get(1)

ac, err := awsConfig()
ac, err := awsConfig(awsConfigArgs(c))
if err != nil {
return err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func runGet(c *cli.Context) error {
func runListGroups(c *cli.Context) error {
prefix := c.String("p")

ac, err := awsConfig()
ac, err := awsConfig(awsConfigArgs(c))
if err != nil {
return err
}
Expand All @@ -181,7 +181,7 @@ func runListStreams(c *cli.Context) error {
return err
}

ac, err := awsConfig()
ac, err := awsConfig(awsConfigArgs(c))
if err != nil {
return err
}
Expand Down

0 comments on commit 61c7350

Please sign in to comment.