Skip to content

Commit

Permalink
Write out AWS_PROFILE and AWS_REGION env
Browse files Browse the repository at this point in the history
Turns out the AWS_DEFAULT_PROFILE was incorrect, reading the SDK's
shows that AWS_PROFILE is used.
  • Loading branch information
lox committed Oct 12, 2015
1 parent 9e910c3 commit b2787b5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,25 @@ func ExecCommand(ui Ui, input ExecCommandInput) {
ui.Error.Fatal(http.Serve(l, proxyHandler(NewMetadataHandler(creds))))
}()

cfg, err := profileConfig(input.Profile)
profs, err := parseProfiles()
if err != nil {
ui.Error.Fatal(cfg)
ui.Error.Fatal(err)
}

cfg, err := writeTempConfig(input.Profile, profs)
if err != nil {
ui.Error.Fatal(err)
}

env := os.Environ()
env = overwriteEnv(env, "http_proxy", "http://"+l.Addr().String())
env = overwriteEnv(env, "no_proxy", "amazonaws.com")
env = overwriteEnv(env, "AWS_CONFIG_FILE", cfg.Name())
env = overwriteEnv(env, "AWS_DEFAULT_PROFILE", input.Profile)
env = overwriteEnv(env, "AWS_PROFILE", input.Profile)

if region, ok := profs[input.Profile]["region"]; ok {
env = overwriteEnv(env, "AWS_REGION", region)
}

if input.WriteEnv {
env = overwriteEnv(env, "AWS_ACCESS_KEY_ID", val.AccessKeyID)
Expand Down Expand Up @@ -105,12 +114,7 @@ func ExecCommand(ui Ui, input ExecCommandInput) {
}

// write out a config excluding role switching keys
func profileConfig(profile string) (*os.File, error) {
conf, err := parseProfiles()
if err != nil {
return nil, err
}

func writeTempConfig(profile string, conf profiles) (*os.File, error) {
tmpConfig, err := ioutil.TempFile(os.TempDir(), "aws-vault")
if err != nil {
return nil, err
Expand Down

0 comments on commit b2787b5

Please sign in to comment.