Skip to content

Commit

Permalink
kreuzwerker#36 | Support named profile configs
Browse files Browse the repository at this point in the history
This respects the format here:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

It also allows using export AWS_PROFILE=<profile> before using `awsu`
  • Loading branch information
cybercyst authored and gesellix committed Sep 3, 2020
1 parent 8bf9f30 commit d7d4dbd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"io/ioutil"
"strings"

"github.com/pkg/errors"
ini "gopkg.in/ini.v1"
Expand Down Expand Up @@ -55,6 +56,10 @@ func Load(files ...string) (Profiles, error) {
continue
}

if strings.HasPrefix(name, "profile") {
name = strings.TrimPrefix(name, "profile ")
}

init:

profile, ok := profiles[name]
Expand Down
2 changes: 1 addition & 1 deletion config/testdata/credentials
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[foo]
[profile foo]
role_arn=arn:aws:iam::123456789012:role/marketingadmin
source_profile=default
external_id=123456
Expand Down
2 changes: 1 addition & 1 deletion config/testdata/merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ output=json
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[foo]
[profile foo]
role_arn=arn:aws:iam::123456789012:role/marketingadmin
source_profile=default
external_id=123456
Expand Down

0 comments on commit d7d4dbd

Please sign in to comment.