From f1b9bcd4d373ae57d200755488942e8a2bf7d539 Mon Sep 17 00:00:00 2001 From: Glenn Nethercutt Date: Mon, 19 Jan 2015 17:36:52 -0500 Subject: [PATCH 1/3] aws/aws.go: support aws_session_token from credentials file --- aws/aws.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/aws.go b/aws/aws.go index cfc42c03..1c72abeb 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -377,6 +377,7 @@ func SharedAuth() (auth Auth, err error) { auth.AccessKey = profile["aws_access_key_id"] auth.SecretKey = profile["aws_secret_access_key"] + auth.Token = profile["aws_session_token"] if auth.AccessKey == "" { err = errors.New("AWS_ACCESS_KEY_ID not found in environment in credentials file") From 7e78603ce58e918ad7c4763164525b52331cf2bb Mon Sep 17 00:00:00 2001 From: Glenn Nethercutt Date: Mon, 19 Jan 2015 18:21:37 -0500 Subject: [PATCH 2/3] unit tests for shared auth via credentials file with a session token --- aws/aws_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/aws/aws_test.go b/aws/aws_test.go index 78cbbaf0..fc8391ae 100644 --- a/aws/aws_test.go +++ b/aws/aws_test.go @@ -135,6 +135,30 @@ func (s *S) TestSharedAuth(c *C) { c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"}) } +func (s *S) TestSharedAuthCredentialsWithToken(c *C) { + os.Clearenv() + os.Setenv("AWS_PROFILE", "bar") + + d, err := ioutil.TempDir("", "") + if err != nil { + panic(err) + } + defer os.RemoveAll(d) + + err = os.Mkdir(d+"/.aws", 0755) + if err != nil { + panic(err) + } + + ioutil.WriteFile(d+"/.aws/credentials", []byte("[bar]\naws_access_key_id = access\naws_secret_access_key = secret\naws_session_token = token\n", 0644) + os.Setenv("HOME", d) + + auth, err := aws.SharedAuth() + c.Assert(err, IsNil) + c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access", Token: "token"}) +} + + func (s *S) TestEnvAuthNoSecret(c *C) { os.Clearenv() _, err := aws.EnvAuth() From d20bc13b30c932d9507c24a011a4ad40079db60e Mon Sep 17 00:00:00 2001 From: Glenn Nethercutt Date: Mon, 19 Jan 2015 21:23:29 -0500 Subject: [PATCH 3/3] blerg, unit test typo --- aws/aws_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/aws_test.go b/aws/aws_test.go index fc8391ae..ddedbfc6 100644 --- a/aws/aws_test.go +++ b/aws/aws_test.go @@ -150,7 +150,7 @@ func (s *S) TestSharedAuthCredentialsWithToken(c *C) { panic(err) } - ioutil.WriteFile(d+"/.aws/credentials", []byte("[bar]\naws_access_key_id = access\naws_secret_access_key = secret\naws_session_token = token\n", 0644) + ioutil.WriteFile(d+"/.aws/credentials", []byte("[bar]\naws_access_key_id = access\naws_secret_access_key = secret\naws_session_token = token\n"), 0644) os.Setenv("HOME", d) auth, err := aws.SharedAuth()