feat(aws): use AWS_DEFAULT_PROFILE for profile name

resolves #4036
This commit is contained in:
Jan De Dobbeleer 2023-07-10 07:47:28 +02:00 committed by Jan De Dobbeleer
parent e6e9d0a66b
commit 69a95bfb38
2 changed files with 4 additions and 1 deletions

View file

@ -40,7 +40,7 @@ func (a *Aws) Enabled() bool {
return ""
}
displayDefaultUser := a.props.GetBool(properties.DisplayDefault, true)
a.Profile = getEnvFirstMatch("AWS_VAULT", "AWS_PROFILE")
a.Profile = getEnvFirstMatch("AWS_VAULT", "AWS_DEFAULT_PROFILE", "AWS_PROFILE")
if !displayDefaultUser && a.Profile == defaultUser {
return false
}

View file

@ -15,6 +15,7 @@ func TestAWSSegment(t *testing.T) {
ExpectedString string
ExpectedEnabled bool
Profile string
DefaultProfile string
Vault string
Region string
DefaultRegion string
@ -26,6 +27,7 @@ func TestAWSSegment(t *testing.T) {
{Case: "disabled with default user", ExpectedString: "default@eu-west", Region: "eu-west", ExpectedEnabled: false, DisplayDefault: false},
{Case: "disabled", ExpectedString: "", ExpectedEnabled: false},
{Case: "enabled with default user", ExpectedString: "default@eu-west", Profile: "default", Region: "eu-west", ExpectedEnabled: true, DisplayDefault: true},
{Case: "enabled with default profile", ExpectedString: "default@eu-west", DefaultProfile: "default", Region: "eu-west", ExpectedEnabled: true, DisplayDefault: true},
{Case: "disabled with default user", ExpectedString: "default", Profile: "default", Region: "eu-west", ExpectedEnabled: false, DisplayDefault: false},
{Case: "enabled no region", ExpectedString: "company", ExpectedEnabled: true, Profile: "company"},
{Case: "enabled with region", ExpectedString: "company@eu-west", ExpectedEnabled: true, Profile: "company", Region: "eu-west", DefaultRegion: "us-west"},
@ -52,6 +54,7 @@ func TestAWSSegment(t *testing.T) {
env := new(mock.MockedEnvironment)
env.On("Getenv", "AWS_VAULT").Return(tc.Vault)
env.On("Getenv", "AWS_PROFILE").Return(tc.Profile)
env.On("Getenv", "AWS_DEFAULT_PROFILE").Return(tc.DefaultProfile)
env.On("Getenv", "AWS_REGION").Return(tc.Region)
env.On("Getenv", "AWS_DEFAULT_REGION").Return(tc.DefaultRegion)
env.On("Getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)