Skip to content

Commit

Permalink
Merge pull request #243 from trek10inc/feat/235-show-current-profile
Browse files Browse the repository at this point in the history
#235 show current profile with 'who' flag
  • Loading branch information
mtskillman authored Nov 22, 2023
2 parents a8e0f83 + 602297b commit fb7a0b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 11 additions & 0 deletions awsume/awsumepy/default_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def add_arguments(config: dict, parser: argparse.ArgumentParser):
dest='with_web_identity',
help='Use web identity (requires plugin)',
)
assume_role_method.add_argument('--who',
action='store_true',
dest='who',
help='Show current/active aws profile',
)
parser.add_argument('--json',
action='store',
dest='json',
Expand Down Expand Up @@ -219,6 +224,12 @@ def post_add_arguments(config: dict, arguments: argparse.Namespace, parser: argp
logger.debug('Logging version')
safe_print(__data__.version)
raise exceptions.EarlyExit()
if arguments.who:
logger.debug('Logging current profile')
awsume_profile = os.getenv('AWSUME_PROFILE')
message = awsume_profile if awsume_profile else 'No profile awsume\'d currently'
safe_print(message)
raise exceptions.EarlyExit()
if arguments.unset_variables:
logger.debug('Unsetting environment variables')
print('Unset', [])
Expand Down
14 changes: 8 additions & 6 deletions test/unit/awsume/awsumepy/test_default_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def generate_namespace_with_defaults(
with_saml=None,
principal_arn=None,
profile_name=None,
who=None,
**kwargs
) -> argparse.Namespace:
return argparse.Namespace(
Expand All @@ -34,6 +35,7 @@ def generate_namespace_with_defaults(
with_saml=with_saml,
principal_arn=principal_arn,
profile_name=profile_name,
who=who,
**kwargs
)

Expand All @@ -56,7 +58,7 @@ def test_add_arguments():
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_role_arn_no_auto_refresh(safe_print: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn=True,
auto_refresh=True,
version=False,
Expand Down Expand Up @@ -98,7 +100,7 @@ def test_post_add_arguments_version(safe_print: MagicMock, stdout: MagicMock, st
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_unset_variables(safe_print: MagicMock, stdout: MagicMock, stderr: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn=False,
auto_refresh=False,
version=False,
Expand All @@ -120,7 +122,7 @@ def test_post_add_arguments_unset_variables(safe_print: MagicMock, stdout: Magic
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_config(safe_print: MagicMock, config_lib: MagicMock, stdout: MagicMock, stderr: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn=False,
auto_refresh=False,
version=False,
Expand All @@ -143,7 +145,7 @@ def test_post_add_arguments_config(safe_print: MagicMock, config_lib: MagicMock,
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_kill(safe_print: MagicMock, kill: MagicMock, stdout: MagicMock, stderr: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn=False,
auto_refresh=False,
version=False,
Expand Down Expand Up @@ -186,7 +188,7 @@ def test_post_add_arguments_role_arn_short(safe_print: MagicMock):
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_role_arn_short_bad_id(safe_print: MagicMock, stdout: MagicMock, stderr: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn='notanid:myrole',
auto_refresh=False,
version=False,
Expand All @@ -209,7 +211,7 @@ def test_post_add_arguments_role_arn_short_bad_id(safe_print: MagicMock, stdout:
@patch.object(default_plugins, 'safe_print')
def test_post_add_arguments_role_arn_short_bad_number_parts(safe_print: MagicMock, stdout: MagicMock, stderr: MagicMock):
config = {}
arguments = argparse.Namespace(
arguments = generate_namespace_with_defaults(
role_arn='notanid:myrole:other',
auto_refresh=False,
version=False,
Expand Down

0 comments on commit fb7a0b4

Please sign in to comment.