Skip to content
Merged
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
12 changes: 6 additions & 6 deletions samcli/commands/pipeline/bootstrap/guided_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ def _prompt_account_id(self) -> None:
"""
)
)
if os.getenv(EnvProvider.ACCESS_KEY) and os.getenv(EnvProvider.SECRET_KEY):
click.echo(f" e. Environment variables: {EnvProvider.ACCESS_KEY} and {EnvProvider.SECRET_KEY}")
has_env_creds = os.getenv(EnvProvider.ACCESS_KEY) and os.getenv(EnvProvider.SECRET_KEY)
click.echo(f" 1. Environment variables{' (not available)' if not has_env_creds else ''}")
for i, profile in enumerate(profiles):
click.echo(f" {i + 1}. {profile} (named profile)")
click.echo(f" {i + 2}. {profile} (named profile)")
click.echo(" q. Quit and configure AWS credential myself")
answer = click.prompt(
"Select an account source to associate with this stage",
show_choices=False,
show_default=False,
type=click.Choice([str(i + 1) for i in range(len(profiles))] + ["q", "e"]),
type=click.Choice((["1"] if has_env_creds else []) + [str(i + 2) for i in range(len(profiles))] + ["q"]),
)
if answer == "q":
sys.exit(0)
elif answer == "e":
elif answer == "1":
# by default, env variable has higher precedence
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list
self.profile = None
else:
self.profile = profiles[int(answer) - 1]
self.profile = profiles[int(answer) - 2]

try:
account_id = get_current_account_id(self.profile)
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/commands/pipeline/bootstrap/test_guided_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ def test_prompt_account_id_can_display_profiles_and_environment(
):
getenv_mock.return_value = "not None"
list_available_profiles_mock.return_value = ["profile1", "profile2"]
click_mock.prompt.return_value = "e" # select environment variable
click_mock.prompt.return_value = "1" # select environment variable
get_current_account_id_mock.return_value = "account_id"

guided_context_mock = Mock()
GuidedContext._prompt_account_id(guided_context_mock)

click_mock.prompt.assert_called_once_with(
ANY, show_choices=False, show_default=False, type=click_mock.Choice(["1", "2", "q", "e"])
ANY, show_choices=False, show_default=False, type=click_mock.Choice(["1", "2", "3", "q"])
)

@patch("samcli.commands.pipeline.bootstrap.guided_context.get_current_account_id")
Expand All @@ -150,14 +150,14 @@ def test_prompt_account_id_wont_show_environment_option_when_it_doesnt_exist(
):
getenv_mock.return_value = None
list_available_profiles_mock.return_value = ["profile1", "profile2"]
click_mock.prompt.return_value = "e" # select environment variable
click_mock.prompt.return_value = "1" # select environment variable
get_current_account_id_mock.return_value = "account_id"

guided_context_mock = Mock()
GuidedContext._prompt_account_id(guided_context_mock)

click_mock.prompt.assert_called_once_with(
ANY, show_choices=False, show_default=False, type=click_mock.Choice(["1", "2", "q"])
ANY, show_choices=False, show_default=False, type=click_mock.Choice(["2", "3", "q"])
)

@patch("samcli.commands.pipeline.bootstrap.guided_context.get_current_account_id")
Expand All @@ -169,7 +169,7 @@ def test_prompt_account_id_select_environment_unset_self_profile(
):
getenv_mock.return_value = "not None"
list_available_profiles_mock.return_value = ["profile1", "profile2"]
click_mock.prompt.return_value = "e" # select environment variable
click_mock.prompt.return_value = "1" # select environment variable
get_current_account_id_mock.return_value = "account_id"

guided_context_mock = Mock()
Expand All @@ -180,11 +180,11 @@ def test_prompt_account_id_select_environment_unset_self_profile(
@parameterized.expand(
[
(
"1",
"2",
"profile1",
),
(
"2",
"3",
"profile2",
),
]
Expand Down