Skip to content

Commit 113f440

Browse files
Merge pull request #7 from t-oki/feature/sts
update for assuming roles
2 parents e356140 + e482520 commit 113f440

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ func main() {
1111
app := cli.NewApp()
1212

1313
app.Flags = []cli.Flag{
14+
cli.StringFlag{
15+
Name: "awscredentialsfile",
16+
Usage: "awsのcredentialsファイル(デフォルトは~/.aws/credential)",
17+
},
1418
cli.StringFlag{
1519
Name: "awsconf",
16-
Usage: "~/.aws/credentialsから環境変数をセット(プロセスの間のみ)",
20+
Usage: "awscredentialsfileから環境変数をセット(プロセスの間のみ)",
1721
},
1822
cli.StringFlag{
1923
Name: "awsregion",

util/util.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
const (
1414
accessKeyID = "AWS_ACCESS_KEY_ID"
1515
secretAccessKey = "AWS_SECRET_ACCESS_KEY"
16+
sessionToken = "AWS_SESSION_TOKEN"
1617
defaultRegion = "AWS_DEFAULT_REGION"
1718
)
1819

@@ -23,14 +24,19 @@ func ConfigAWS(c *cli.Context) error {
2324
if name == "" {
2425
return nil
2526
}
26-
cred := credentials.NewSharedCredentials("", name)
27+
file := c.GlobalString("awscredentialsfile")
28+
if file == "" {
29+
file = "~/.aws/credential"
30+
}
31+
cred := credentials.NewSharedCredentials(file, name)
2732
credValue, err := cred.Get()
2833
if err != nil {
2934
return err
3035
}
31-
PrintlnGreen(fmt.Sprintf("AWS Profile Name: %s, Region: %s", name, region))
36+
PrintlnGreen(fmt.Sprintf("AWS Credentials File: %s, AWS Profile Name: %s, Region: %s", file, name, region))
3237
os.Setenv(accessKeyID, credValue.AccessKeyID)
3338
os.Setenv(secretAccessKey, credValue.SecretAccessKey)
39+
os.Setenv(sessionToken, credValue.SessionToken)
3440
return nil
3541
}
3642

0 commit comments

Comments
 (0)