From 07417725a27760eff0210a4b92a9f11954c1b921 Mon Sep 17 00:00:00 2001 From: Johanan Liebermann Date: Mon, 10 Sep 2018 18:40:25 +0200 Subject: [PATCH 1/4] Add missing blank line before return --- aws/aws.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/aws.go b/aws/aws.go index dbde9c5..994845f 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -44,6 +44,7 @@ func WriteToFile(c *Credentials, filename string, section string) error { } } } + return cfg.SaveTo(filename) } From 7db3deda4ffee163d3414a51b80dad600bcb97b2 Mon Sep 17 00:00:00 2001 From: Johanan Liebermann Date: Mon, 10 Sep 2018 18:42:50 +0200 Subject: [PATCH 2/4] Improve documentation --- aws/aws.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws/aws.go b/aws/aws.go index 994845f..9f1e2d9 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -21,6 +21,9 @@ type Credentials struct { // WriteToFile writes credentials to an AWS CLI credentials file // (https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html). +// +// In addition, this function will remove expired temporary credentials +// from the credentials file. func WriteToFile(c *Credentials, filename string, section string) error { cfg, err := ini.LooseLoad(filename) if err != nil { @@ -32,6 +35,7 @@ func WriteToFile(c *Credentials, filename string, section string) error { cfg.Section(section).NewKey("aws_session_token", c.SessionToken) cfg.Section(section).NewKey("aws_expiration", c.Expiration.UTC().Format(time.RFC3339)) + // Remove expired credentials. for _, s := range cfg.Sections() { if s.HasKey("aws_expiration") { v, err := s.Key("aws_expiration").TimeFormat(time.RFC3339) From 4b06032297d1990ca49621b0539e0312800ecb52 Mon Sep 17 00:00:00 2001 From: Johanan Liebermann Date: Mon, 10 Sep 2018 18:42:56 +0200 Subject: [PATCH 3/4] Break long line --- aws/aws.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aws/aws.go b/aws/aws.go index 9f1e2d9..4bb94de 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -44,7 +44,8 @@ func WriteToFile(c *Credentials, filename string, section string) error { cfg.DeleteSection(s.Name()) } } else { - log.Printf(color.YellowString("Cannot parse date (%v) in section %s: %s", s.Key("aws_expiration")), s.Name(), err) + log.Printf(color.YellowString("Cannot parse date (%v) in section %s: %s", + s.Key("aws_expiration")), s.Name(), err) } } } From a869ce52a1c8e467af287640350402a1a52f1f15 Mon Sep 17 00:00:00 2001 From: Johanan Liebermann Date: Mon, 10 Sep 2018 18:44:27 +0200 Subject: [PATCH 4/4] Edit comment --- aws/aws.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/aws/aws.go b/aws/aws.go index 4bb94de..eb63ff4 100644 --- a/aws/aws.go +++ b/aws/aws.go @@ -20,10 +20,8 @@ type Credentials struct { } // WriteToFile writes credentials to an AWS CLI credentials file -// (https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html). -// -// In addition, this function will remove expired temporary credentials -// from the credentials file. +// (https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html). In addition, this +// function removes expired temporary credentials from the credentials file. func WriteToFile(c *Credentials, filename string, section string) error { cfg, err := ini.LooseLoad(filename) if err != nil {