diff --git a/awsmfa/__main__.py b/awsmfa/__main__.py index 08c684c..42990a4 100755 --- a/awsmfa/__main__.py +++ b/awsmfa/__main__.py @@ -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 @@ -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 @@ -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] diff --git a/setup.py b/setup.py index 6561c4e..2aa15ae 100644 --- a/setup.py +++ b/setup.py @@ -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': [