From d7d4dbd43636813cb876c38572ac75914f670855 Mon Sep 17 00:00:00 2001 From: Forrest Loomis Date: Mon, 3 Feb 2020 11:45:36 -0500 Subject: [PATCH] #36 | Support named profile configs This respects the format here: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html It also allows using export AWS_PROFILE= before using `awsu` --- config/profiles.go | 5 +++++ config/testdata/credentials | 2 +- config/testdata/merged | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config/profiles.go b/config/profiles.go index 3f8e882..a57a6f1 100644 --- a/config/profiles.go +++ b/config/profiles.go @@ -2,6 +2,7 @@ package config import ( "io/ioutil" + "strings" "github.com/pkg/errors" ini "gopkg.in/ini.v1" @@ -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] diff --git a/config/testdata/credentials b/config/testdata/credentials index de1686e..50e0794 100644 --- a/config/testdata/credentials +++ b/config/testdata/credentials @@ -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 diff --git a/config/testdata/merged b/config/testdata/merged index efb3c46..558f7be 100644 --- a/config/testdata/merged +++ b/config/testdata/merged @@ -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