From fc77b5e2bad8740cdde0d9d8aaf2fb4b29c3ecd8 Mon Sep 17 00:00:00 2001 From: Laica Lunasys Date: Wed, 28 Jul 2021 16:45:56 +0900 Subject: [PATCH] Add more-options --- README.md | 5 ++--- awsctx.sh | 14 +++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1274a88..7505c36 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,8 @@ awsctx() { # Uncomment me If you want to use CLI based 2FA # MFA_TOKEN=$(oathtool -b --totp $AWS_MFA_SECRET) # --- - if [ "$MFA_TOKEN" != "" ]; then - bash $AWSCTX/awsctx.sh $@ $MFA_TOKEN + bash $AWSCTX/awsctx.sh $1 $MFA_TOKEN $([ "$#" -gt 1 ] && shift 1 && echo $@) else bash $AWSCTX/awsctx.sh $@ fi @@ -29,7 +28,7 @@ sync-aws-profile ## Usage ```bash -awsctx [MFA_TOKEN] +awsctx [MFA_TOKEN] [login|list-roles|console|...] # If you defined MFA_TOKEN: `awsctx myservice-production` # or else: `awsctx myservice-production 123456` ``` diff --git a/awsctx.sh b/awsctx.sh index 4f0a0fe..f1c18e0 100755 --- a/awsctx.sh +++ b/awsctx.sh @@ -4,10 +4,12 @@ cd "$(dirname "$0")" _TARGET="$1" _MFA_TOKEN="$2" +_OPTIONS="$3" _login() { _account="$1" _mfa="$2" + _options="$3" echo ":: Logging in to: $_account" saml2aws login -a $_account \ --skip-prompt \ @@ -16,16 +18,22 @@ _login() { echo ":: Update AWS_PROFILE: $_account" touch $PWD/aws_profile echo "$_account" > $PWD/aws_profile + + if [ "$_options" != "" ]; then + saml2aws $_options $(shift 3 && echo $@) -a $_account \ + --skip-prompt \ + --mfa-token="$_mfa" + fi } if [ "$_TARGET" == "all" ]; then for e in $(cat ~/.saml2aws | grep "\[*\]" | cat); do _a=$(echo $e | tr -d '[]') - _login $_a $_MFA_TOKEN + _login $_a $_MFA_TOKEN $_OPTIONS $(shift 3 && echo $@) done elif [ "$_TARGET" != "" ] && [ "$_MFA_TOKEN" != "" ]; then - _login $_TARGET $_MFA_TOKEN + _login $_TARGET $_MFA_TOKEN $_OPTIONS $(shift 3 && echo $@) else - echo "Usage: awsctx " + echo "Usage: awsctx [MFA_TOKEN] [login|list-roles|console]" exit 1 fi