Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine SSO configure prompt titles #9203

Open
wants to merge 7 commits into
base: v2
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-sso-858.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "configure",
"description": "Clarify prompt titles and default values in the ``aws configure sso`` wizard"
}
25 changes: 16 additions & 9 deletions awscli/customizations/configure/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def _prompt_for_profile(self, sso_account_id=None, sso_role_name=None):
if self._original_profile_name:
profile_name = self._original_profile_name
else:
text = 'CLI profile name'
text = 'Profile name'
default_profile = None
if sso_account_id and sso_role_name:
default_profile = f'{sso_role_name}-{sso_account_id}'
Expand All @@ -478,16 +478,17 @@ def _prompt_for_profile(self, sso_account_id=None, sso_role_name=None):
def _prompt_for_cli_default_region(self):
# TODO: figure out a way to get a list of reasonable client regions
return self._prompt_for_profile_config(
'region', 'CLI default client Region')
'region', 'Default client Region')

def _prompt_for_cli_output_format(self):
return self._prompt_for_profile_config(
'output', 'CLI default output format',
'output', 'CLI default output format (json if not specified)',
completions=list(CLI_OUTPUT_FORMATS.keys()),
)

def _prompt_for_profile_config(self, config_name, text, completions=None):
current_value = self._profile_config.get(config_name)

new_value = self._prompter.get_value(
current_value, text,
completions=completions,
Expand Down Expand Up @@ -651,16 +652,22 @@ def _write_new_config(self, profile):

def _print_conclusion(self, configured_for_aws_credentials, profile_name):
if configured_for_aws_credentials:
msg = (
'\nTo use this profile, specify the profile name using '
'--profile, as shown:\n\n'
'aws s3 ls --profile {}\n'
)
if profile_name.lower() == 'default':
msg = (
'The AWS CLI is now configured to use the default profile.\n'
'Run the following command to verify your configuration:\n\n'
'aws sts get-caller-identity\n'
)
else:
msg = (
'To use this profile, specify the profile name using '
'--profile, as shown:\n\n'
'aws sts get-caller-identity --profile {}\n'
)
else:
msg = 'Successfully configured SSO for profile: {}\n'
uni_print(msg.format(profile_name))


class ConfigureSSOSessionCommand(BaseSSOConfigurationCommand):
NAME = 'sso-session'
SYNOPSIS = ('aws configure sso-session')
Expand Down
42 changes: 37 additions & 5 deletions tests/unit/customizations/configure/test_sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,21 +674,21 @@ class SessionWithDefaultPrompt(PromptWithDefault):
@dataclasses.dataclass
class RegionPrompt(PromptWithDefault):
msg_format: str = dataclasses.field(
init=False, default="CLI default client Region [{default}]: "
init=False, default="Default client Region [{default}]: "
)


@dataclasses.dataclass
class OutputPrompt(PromptWithDefault):
msg_format: str = dataclasses.field(
init=False, default="CLI default output format [{default}]: "
init=False, default="CLI default output format (json if not specified) [{default}]: "
)


@dataclasses.dataclass
class ProfilePrompt(PromptWithDefault):
msg_format: str = dataclasses.field(
init=False, default="CLI profile name [{default}]: "
init=False, default="Profile name [{default}]: "
)
expected_validator_cls: typing.Optional[Validator] = RequiredInputValidator

Expand Down Expand Up @@ -902,7 +902,7 @@ def test_legacy_configure_sso_flow(
)
stdout = capsys.readouterr().out
assert "WARNING: Configuring using legacy format" in stdout
assert f"aws s3 ls --profile {inputs.profile_prompt.answer}" in stdout
assert f"aws sts get-caller-identity --profile {inputs.profile_prompt.answer}" in stdout

def test_single_account_single_role_flow_no_browser(
self,
Expand Down Expand Up @@ -1099,6 +1099,7 @@ def test_handles_non_existent_profile(
expected_sso_region=inputs.sso_region_prompt.answer,
expected_start_url=inputs.start_url_prompt.answer,
)

assert_aws_config(
aws_config,
expected_lines=[
Expand Down Expand Up @@ -1235,7 +1236,7 @@ def test_configure_sso_with_new_sso_session(
)
stdout = capsys.readouterr().out
assert "WARNING: Configuring using legacy format" not in stdout
assert f"aws s3 ls --profile {inputs.profile_prompt.answer}" in stdout
assert f"aws sts get-caller-identity --profile {inputs.profile_prompt.answer}" in stdout

def test_configure_sso_with_existing_sso_session(
self,
Expand Down Expand Up @@ -1513,6 +1514,37 @@ def test_single_account_single_role_device_code_fallback(
],
)

class TestPrintConclusion:
def test_print_conclusion_default_profile_with_credentials(self, sso_cmd, capsys):
sso_cmd._print_conclusion(True, 'default')
captured = capsys.readouterr()
assert "The AWS CLI is now configured to use the default profile." in captured.out
assert "aws sts get-caller-identity" in captured.out

def test_print_conclusion_named_profile_with_credentials(self, sso_cmd, capsys):
profile_name = "test-profile"
sso_cmd._print_conclusion(True, profile_name)
captured = capsys.readouterr()
assert f"To use this profile, specify the profile name using --profile" in captured.out
assert f"aws sts get-caller-identity --profile {profile_name}" in captured.out

def test_print_conclusion_sso_configuration(self, sso_cmd, capsys):
profile_name = "test-profile"
sso_cmd._print_conclusion(False, profile_name)
captured = capsys.readouterr()
assert f"Successfully configured SSO for profile: {profile_name}" in captured.out

def test_print_conclusion_default_profile_case_insensitive(selfself, sso_cmd, capsys):
sso_cmd._print_conclusion(True, 'DEFAULT')
captured = capsys.readouterr()
assert "The AWS CLI is now configured to use the default profile." in captured.out
assert "aws sts get-caller-identity" in captured.out

def test_print_conclusion_empty_profile_name(self, sso_cmd, capsys):
sso_cmd._print_conclusion(True, '')
captured = capsys.readouterr()
assert "To use this profile, specify the profile name using --profile" in captured.out
assert "aws sts get-caller-identity --profile" in captured.out

class TestConfigureSSOSessionCommand:
def test_new_sso_session(
Expand Down
Loading