Skip to content

Commit

Permalink
Merge pull request #39 from 99designs/unset-aws-envs
Browse files Browse the repository at this point in the history
Some AWS env vars need to be unset, e.g AWS_CREDENTIAL_FILE
  • Loading branch information
lox committed Oct 12, 2015
2 parents b2787b5 + 0a67849 commit 7bf44ad
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func ExecCommand(ui Ui, input ExecCommandInput) {
env = overwriteEnv(env, "no_proxy", "amazonaws.com")
env = overwriteEnv(env, "AWS_CONFIG_FILE", cfg.Name())
env = overwriteEnv(env, "AWS_PROFILE", input.Profile)
env = unsetEnv(env, "AWS_CREDENTIAL_FILE")

if region, ok := profs[input.Profile]["region"]; ok {
env = overwriteEnv(env, "AWS_REGION", region)
Expand Down Expand Up @@ -135,6 +136,18 @@ func writeTempConfig(profile string, conf profiles) (*os.File, error) {
return tmpConfig, writeProfiles(tmpConfig, profiles{profile: newConfig})
}

func unsetEnv(env []string, key string) []string {
envCopy := []string{}

for _, e := range env {
if !strings.HasPrefix(key+"=", e) {
envCopy = append(envCopy, e)
}
}

return envCopy
}

func overwriteEnv(env []string, key, val string) []string {
var found bool

Expand Down

0 comments on commit 7bf44ad

Please sign in to comment.