From 21689818e9bd9557ee14a265cbda481c9f55334b Mon Sep 17 00:00:00 2001 From: George Geddes Date: Fri, 22 Dec 2023 17:16:24 -0500 Subject: [PATCH 1/3] Allow target variables to be passed from the environment --- aws-cli/get-aws-subaccount-session.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/aws-cli/get-aws-subaccount-session.sh b/aws-cli/get-aws-subaccount-session.sh index c0c5646..eb93452 100755 --- a/aws-cli/get-aws-subaccount-session.sh +++ b/aws-cli/get-aws-subaccount-session.sh @@ -47,13 +47,15 @@ echo echo Loading AWS CLI configs... echo -#### alter the values below to your target subaccount and target role as needed ## - -export AWS_PROFILE=default -export aws_target_subaccount_name=gross-eng-dev -export aws_target_subaccount_id=235758441054 -export aws_target_subaccount_role=isc-login_assumed-role_eng_power-users -export aws_target_subaccount_session_seconds=3600 +#### alter the values below to your target subaccount and target role as needed ## +#### You may set these environment variables before sourcing the +#### script to override the default values. + +export AWS_PROFILE=${AWS_PROFILE:-default} +export aws_target_subaccount_name=${aws_target_subaccount_name:-gross-eng-dev} +export aws_target_subaccount_id=${aws_target_subaccount_id:-235758441054} +export aws_target_subaccount_role=${aws_target_subaccount_role:-isc-login_assumed-role_eng_power-users} +export aws_target_subaccount_session_seconds=${aws_target_subaccount_session_seconds:-3600} ################################################################################## From 68c56569243553d764b2a112b72fdda7d1db6848 Mon Sep 17 00:00:00 2001 From: George Geddes Date: Fri, 22 Dec 2023 17:00:33 -0500 Subject: [PATCH 2/3] Don't require a TTY --- aws-cli/get-aws-subaccount-session.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/aws-cli/get-aws-subaccount-session.sh b/aws-cli/get-aws-subaccount-session.sh index eb93452..a92ee2b 100755 --- a/aws-cli/get-aws-subaccount-session.sh +++ b/aws-cli/get-aws-subaccount-session.sh @@ -120,17 +120,10 @@ echo #### this content is sourced from https://github.com/sweharris/aws-cli-mfa/blob/master/get-aws-creds and has been modified a bit ## -# This uses MFA devices to get temporary (eg 12 hour) credentials. Requires -# a TTY for user input. +# This uses MFA devices to get temporary (eg 1 hour) credentials. # # GPL 2 or higher -if [ ! -t 0 ] -then - echo Must be on a tty >&2 - return -fi - if [ -n "$AWS_SESSION_TOKEN" ] then echo "Session token found. This can not be used to generate a new token. From df0eac57e0aa45287bd3f9bf230fc8337cc0b884 Mon Sep 17 00:00:00 2001 From: George Geddes Date: Fri, 22 Dec 2023 17:26:52 -0500 Subject: [PATCH 3/3] Revert "Don't require a TTY" This reverts commit 68c56569243553d764b2a112b72fdda7d1db6848. --- aws-cli/get-aws-subaccount-session.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aws-cli/get-aws-subaccount-session.sh b/aws-cli/get-aws-subaccount-session.sh index a92ee2b..eb93452 100755 --- a/aws-cli/get-aws-subaccount-session.sh +++ b/aws-cli/get-aws-subaccount-session.sh @@ -120,10 +120,17 @@ echo #### this content is sourced from https://github.com/sweharris/aws-cli-mfa/blob/master/get-aws-creds and has been modified a bit ## -# This uses MFA devices to get temporary (eg 1 hour) credentials. +# This uses MFA devices to get temporary (eg 12 hour) credentials. Requires +# a TTY for user input. # # GPL 2 or higher +if [ ! -t 0 ] +then + echo Must be on a tty >&2 + return +fi + if [ -n "$AWS_SESSION_TOKEN" ] then echo "Session token found. This can not be used to generate a new token.