Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/aws/access_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,16 @@ func TestStripAndReturnProfileFlag(t *testing.T) {
expectedArgs: []string{"--", "wrapped command", "--profile", "dev"},
expectedFlagValue: "",
},
{
args: []string{"iam", "get-user", "--profile", "alice", "--user-name", "alice"},
expectedArgs: []string{"iam", "get-user", "--user-name", "alice"},
expectedFlagValue: "alice",
},
{
args: []string{"iam", "get-user", "--profile=alice", "--user-name", "alice"},
expectedArgs: []string{"iam", "get-user", "--user-name", "alice"},
expectedFlagValue: "alice",
},
} {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
flag, args, err := stripAndReturnProfileFlag(scenario.args)
Expand Down
7 changes: 5 additions & 2 deletions plugins/aws/cli_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func stripAndReturnProfileFlag(args []string) (string, []string, error) {
var profileValue string
var newArgs []string
commandOptionsEnded := false
for i, arg := range args {
for i := 0; i < len(args); i++ {
arg := args[i]
// if `--profile` is used after `--`, it should not be interpreted as a flag
if arg == "--" {
commandOptionsEnded = true
Expand All @@ -39,12 +40,14 @@ func stripAndReturnProfileFlag(args []string) (string, []string, error) {
return "", nil, fmt.Errorf("--profile flag was specified without a value")
}
profileValue = args[i+1]
// skip the value too, so later arguments equal to the profile name are kept
i++
} else if !commandOptionsEnded && strings.HasPrefix(arg, "--profile=") {
profileValue = strings.TrimPrefix(arg, "--profile=")
if profileValue == "" {
return "", nil, fmt.Errorf("--profile flag was specified without a value")
}
} else if commandOptionsEnded || arg != profileValue {
} else {
// make sure only profile specification args are removed from the command line so that aws cli does not attempt to assume a role by itself.
newArgs = append(newArgs, arg)
}
Expand Down
Loading