Skip to content

Commit

Permalink
Merge pull request #3 from remind101/deal_with_dup_variables
Browse files Browse the repository at this point in the history
Allow update of existing env vars
  • Loading branch information
phobologic committed Feb 9, 2016
2 parents 25dfc34 + 43289e8 commit ac01f41
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,25 @@ func execWithCredentials(argv []string, creds *credentials) error {
return err
}

os.Setenv("AWS_ACCESS_KEY_ID", creds.AccessKeyID)
os.Setenv("AWS_SECRET_ACCESS_KEY", creds.SecretAccessKey)
os.Setenv("AWS_SESSION_TOKEN", creds.SessionToken)
os.Setenv("AWS_SECURITY_TOKEN", creds.SessionToken)

env := os.Environ()
env = append(env, fmt.Sprintf("AWS_ACCESS_KEY_ID=%s", creds.AccessKeyId))
env = append(env, fmt.Sprintf("AWS_SECRET_ACCESS_KEY=%s", creds.SecretAccessKey))
env = append(env, fmt.Sprintf("AWS_SESSION_TOKEN=%s", creds.SessionToken))
env = append(env, fmt.Sprintf("AWS_SECURITY_TOKEN=%s", creds.SessionToken))
return syscall.Exec(argv0, argv, env)
}

type credentials struct {
AccessKeyId string
AccessKeyID string
SecretAccessKey string
SessionToken string
}

// printCredentials prints the credentials in a way that can easily be sourced
// with bash.
func printCredentials(creds *credentials) {
fmt.Printf("export AWS_ACCESS_KEY_ID=\"%s\"\n", creds.AccessKeyId)
fmt.Printf("export AWS_ACCESS_KEY_ID=\"%s\"\n", creds.AccessKeyID)
fmt.Printf("export AWS_SECRET_ACCESS_KEY=\"%s\"\n", creds.SecretAccessKey)
fmt.Printf("export AWS_SESSION_TOKEN=\"%s\"\n", creds.SessionToken)
fmt.Printf("export AWS_SECURITY_TOKEN=\"%s\"\n", creds.SessionToken)
Expand Down

0 comments on commit ac01f41

Please sign in to comment.