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

Handle invalid --role-arn input #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions aws_role_credentials/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ def exec_handler(region, exec_command, **kwargs):
def saml_token(region, assertion, **kwargs):
assertion = SamlAssertion(assertion)
roles = assertion.roles()
if kwargs.get('role_arn', False):
for i, role in enumerate(roles):
if role['role'] == kwargs['role_arn']:
role = roles[i]
break

# If the user provided --role-arn attempt to find that role
if kwargs.get('role_arn'):
role = next((role for role in roles if role['role'] == kwargs['role_arn']), None)
if role is None:
raise LookupError("Unable to find '--role-arn {}'".format(kwargs['role_arn']))
# If user hasn't provided --role-arn and if the list of roles is > 1, prompt the user to select a role
elif len(roles) > 1:
print('Please select the role you would like to assume:')
for i, role in enumerate(roles):
Expand All @@ -93,6 +95,7 @@ def saml_token(region, assertion, **kwargs):
break
except (IndexError, ValueError):
print('Invalid selection, please try again...')
# Default to the first role in the list of roles
else:
role = roles[0]

Expand Down