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

Support setting the suffixes via environment variables. #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ Usage
identify the long term credential section by
[<profile_name>]. Omit to identify the long term
credential section by [<profile_name>-long-term].
The value can also be provided via the environment
variable 'MFA_LONG_TERM_SUFFIX.
--short-term-suffix SHORT_TERM_SUFFIX
To identify the short term credential section by
[<profile_name>-SHORT_TERM_SUFFIX]. Omit or use 'none'
to identify the short term credential section by
[<profile_name>].
[<profile_name>]. The value can also be provided via
the environment variable 'MFA_SHORT_TERM_SUFFIX.
--assume-role arn:aws:iam::123456788990:role/RoleName
The ARN of the AWS IAM Role you would like to assume,
if specified. This value can also be provided via the
Expand Down
19 changes: 14 additions & 5 deletions awsmfa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,31 @@ def validate(args, config):
args.profile = 'default'

if not args.long_term_suffix:
long_term_name = '%s-long-term' % (args.profile,)
elif args.long_term_suffix.lower() == 'none':
long_term_name = args.profile
if os.environ.get('MFA_LONG_TERM_SUFFIX'):
args.long_term_suffix = os.environ.get('MFA_LONG_TERM_SUFFIX')
long_term_name = '%s-%s' % (args.profile, args.long_term_suffix)
else:
long_term_name = '%s-long-term' % (args.profile,)
else:
long_term_name = '%s-%s' % (args.profile, args.long_term_suffix)
if args.long_term_suffix.lower() == 'none':
long_term_name = args.profile
logger.debug('Using long term name: %s' % (long_term_name,))

if not args.short_term_suffix or args.short_term_suffix.lower() == 'none':
short_term_name = args.profile
if os.environ.get('MFA_SHORT_TERM_SUFFIX'):
args.short_term_suffix = os.environ.get('MFA_SHORT_TERM_SUFFIX')
short_term_name = '%s-%s' % (args.profile, args.short_term_suffix)
else:
short_term_name = args.profile
else:
short_term_name = '%s-%s' % (args.profile, args.short_term_suffix)
logger.debug('Using short term name: %s' % (short_term_name,))

if long_term_name == short_term_name:
log_error_and_exit(logger,
"The value for '--long-term-suffix' cannot "
"be equal to the value for '--short-term-suffix'")

if args.assume_role:
role_msg = "with assumed role: %s" % (args.assume_role,)
elif config.has_option(args.profile, 'assumed_role_arn'):
Expand Down