Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
fix preserving existing aws credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfoo committed Jun 28, 2016
1 parent f759249 commit 2d5038b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions commands/assume.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ func (c *CmdAssume) getArnOfAliasFromFile(rolesFile string) string {
}

func (c *CmdAssume) saveAWSCredentials(credentialsFile string) error {
cfg := ini.Empty()
cfg, err := ini.LooseLoad(awsCredentialsFile)

if err != nil {
fmt.Println("Creating new credentials file...")
}

cfg.NewSection(c.awsSession)
cfg.Section(c.awsSession).NewKey("aws_access_key_id", c.credentials.AccessKey)
cfg.Section(c.awsSession).NewKey("aws_secret_access_key", c.credentials.SecretKey)
cfg.Section(c.awsSession).NewKey("aws_security_token", c.credentials.Token)

err := cfg.SaveTo(awsCredentialsFile)
err = cfg.SaveTo(awsCredentialsFile)

if err != nil {
return err
Expand Down
15 changes: 12 additions & 3 deletions commands/configure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package commands

import "gopkg.in/ini.v1"
import (
"fmt"

"gopkg.in/ini.v1"
)

type CmdConfigure struct {
Alias string `short:"a" long:"alias" description:"role alias" default:"default"`
Expand All @@ -9,11 +13,16 @@ type CmdConfigure struct {
}

func (c *CmdConfigure) Execute(args []string) error {
cfg := ini.Empty()
cfg, err := ini.LooseLoad(c.RolesFile)

if err != nil {
fmt.Println("Creating new roles file...")
}

cfg.NewSection(c.Alias)
cfg.Section(c.Alias).NewKey("arn", c.Arn)

err := cfg.SaveTo(c.RolesFile)
err = cfg.SaveTo(c.RolesFile)

if err != nil {
return err
Expand Down

0 comments on commit 2d5038b

Please sign in to comment.