-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add interactive prompt for AWS profile name #111
Add interactive prompt for AWS profile name #111
Conversation
@pcmxgti I don't think I have the ability to assign team members to this PR. Is that something you can do? |
a07fd4b
to
f1a9141
Compare
Sorry for all the bad commits and spam. I finally got my local dev environment working and am able to run |
@opis-mark No worries about the commits, keep them coming, it is much appreciated! I will give this more time over the weekend. Thanks!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @opis-mark , Thank you so much for this PR, it is a nice feature.
If you could make some minor changes - basically to only call the set method from tool.py, and name change, as:
diff --git a/tests/unit_test.py b/tests/unit_test.py
index 87ae1de..0a83d29 100644
--- a/tests/unit_test.py
+++ b/tests/unit_test.py
@@ -1182,15 +1182,15 @@ def test_process_interactive_input(mocker):
("role_name", "role_name", "role_name"),
],
)
-def test_get_profile_name(mocker, default, submit, expected):
+def test_get_interactive_profile_name(mocker, default, submit, expected):
"""Test getting the AWS profile name form user input."""
from tokendito import user
mocker.patch("tokendito.user.input", return_value=submit)
- assert user.get_profile_name(default) == expected
+ assert user.get_interactive_profile_name(default) == expected
-def test_get_profile_name_invalid_input(monkeypatch):
+def test_get_interactive_profile_name_invalid_input(monkeypatch):
"""Test reprompting the AWS profile name form user on invalid input."""
from tokendito import user
@@ -1200,7 +1200,7 @@ def test_get_profile_name_invalid_input(monkeypatch):
# using lambda statement for mocking
monkeypatch.setattr("builtins.input", lambda name: next(inputs))
- assert user.get_profile_name("role_name") == "valid"
+ assert user.get_interactive_profile_name("role_name") == "valid"
@pytest.mark.parametrize(
diff --git a/tokendito/tool.py b/tokendito/tool.py
index 6494b8d..bd2e150 100644
--- a/tokendito/tool.py
+++ b/tokendito/tool.py
@@ -63,11 +63,7 @@ def cli(args):
)
sys.exit(1)
- profile_name = config.aws["profile"]
- if profile_name is None or profile_name == "":
- profile_name = user.get_profile_name(role_name)
-
- user.set_profile_name(config, profile_name)
+ user.set_profile_name(config, role_name)
user.set_local_credentials(
response=role_response,
diff --git a/tokendito/user.py b/tokendito/user.py
index 8432896..b82e84b 100644
--- a/tokendito/user.py
+++ b/tokendito/user.py
@@ -864,7 +864,7 @@ def get_password():
return res
-def get_profile_name(default):
+def get_interactive_profile_name(default):
"""Get AWS profile name from user.
:return: string with sanitized value, or the default string.
@@ -886,17 +886,14 @@ def get_profile_name(default):
return res
-def set_profile_name(config_obj, name):
+def set_profile_name(config_obj, role_name):
"""Set AWS Role alias name based on user preferences.
:param config: Config object.
- :param name: Role name. Defaults to the string "default"
:return: Config object.
"""
- if name is None or name == "":
- name = "default"
- if config_obj.aws["profile"] is None:
- config_obj.aws["profile"] = str(name)
+ if config.aws["profile"] is None or config.aws["profile"] == "":
+ config.aws["profile"] = get_interactive_profile_name(role_name)
return config_obj
Thank you very much!
@sevignyj - I've got your changes made locally but I could use a recommendation for the user.set_profile_name tests. It's not obvious to me if role_name can ever be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @opis-mark , looks great!
Description
Ask the user what name to give the AWS credential profile after the role is selected.
Related Issue
#110
Motivation and Context
Currently the AWS profile is defaulted to the IAM role name but this is not specific enough for my needs as I have access to multiple accounts with matching role names. I prefix my profile names with the AWS account name so that I can have confidence that I am working in the correct environment.
How Has This Been Tested?
I ran through the interactive prompts and the output worked as expected. I then tested the local profile and was able to successfully execute commands with the AWS cli using the generated credentials. More testing should be done to validate expected behavior when environment variables, saved config files, or command line options which should exclude the prompt from being displayed.
Types of changes
Checklist: