Skip to content
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
16 changes: 14 additions & 2 deletions awsmfa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import botocore.exceptions
import botocore.session
import pytz
import questionary
from six import PY2
# noinspection PyUnresolvedReferences
from six.moves import configparser
Expand Down Expand Up @@ -332,6 +333,16 @@ def safe_bool(s):
return str(s).lower() == "true"


def choose(message, choices):
try:
stdout = sys.stdout
sys.stdout = sys.stderr
choice = questionary.select(message, choices).ask()
finally:
sys.stdout = stdout
return choice


def find_mfa_for_user(user_specified_serial, botocore_session, boto3_session):
if user_specified_serial:
return user_specified_serial
Expand All @@ -357,8 +368,9 @@ def find_mfa_for_user(user_specified_serial, botocore_session, boto3_session):
if not serials:
return None
if len(serials) > 1:
print("Warning: user has %d MFA devices. Using the first." %
len(devices), file=sys.stderr)
print("Warning: user has %d MFA devices." %
len(serials), file=sys.stderr)
return choose("Select device to use:", serials)
return serials[0]


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def get_version():
'botocore>=1.12.216',
'boto3>=1.9.216',
'pytz>=2016.1',
'six>=1.10.0'
'six>=1.10.0',
'questionary'
],
entry_points={
'console_scripts': [
Expand Down