-
-
Save davewongillies/5f3ec1a271b7fd5b0e1fb24eb761c0ba to your computer and use it in GitHub Desktop.
Revisions
-
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ function aws_config if test $AWS_SESSION_EXPIRY set now (date +%s) # WARNING: this date command only works with GNU date set expiry (date -d $AWS_SESSION_EXPIRY +%s) if [ $now -gt $expiry ] -
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,17 +3,15 @@ function aws_config echo "Please specify a valid profile." else set token_expired false if test $AWS_SESSION_EXPIRY set now (date +%s) set expiry (date -d $AWS_SESSION_EXPIRY +%s) if [ $now -gt $expiry ] set -e AWS_SESSION_EXPIRY set token_expired true end end -
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,8 +33,7 @@ function aws_config --token-code=$mfa_token \ --duration-seconds $duration \ --output text \ --query 'Credentials | join (`;`,values({ AccessKeyId: join(``, [`set -Ux AWS_ACCESS_KEY_ID `,AccessKeyId]), SecretAccessKey:join(``, [`set -Ux AWS_SECRET_ACCESS_KEY `,SecretAccessKey]), SessionToken:join(``, [`set -Ux AWS_SESSION_TOKEN `,SessionToken]), Expiration:join(``, [`set -Ux AWS_SESSION_EXPIRY `,Expiration]) }))' ) fish -c $aws_cli end -
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,10 +34,7 @@ function aws_config --duration-seconds $duration \ --output text \ --query 'Credentials | join (`;`,values({ \ AccessKeyId: join(``, [`set -Ux AWS_ACCESS_KEY_ID `,AccessKeyId]), SecretAccessKey:join(``, [`set -Ux AWS_SECRET_ACCESS_KEY `,SecretAccessKey]), SessionToken:join(``, [`set -Ux AWS_SESSION_TOKEN `,SessionToken]), Expiration:join(``, [`set -Ux AWS_SESSION_EXPIRY `,Expiration]) }))' ) fish -c $aws_cli end -
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,8 +33,11 @@ function aws_config --token-code=$mfa_token \ --duration-seconds $duration \ --output text \ --query 'Credentials | join (`;`,values({ \ AccessKeyId: join(``, [`set -Ux AWS_ACCESS_KEY_ID `,AccessKeyId]), \ SecretAccessKey:join(``, [`set -Ux AWS_SECRET_ACCESS_KEY `,SecretAccessKey]), \ SessionToken:join(``, [`set -Ux AWS_SESSION_TOKEN `,SessionToken]), \ Expiration:join(``, [`set -Ux AWS_SESSION_EXPIRY `,Expiration]) }))' ) fish -c $aws_cli end -
davewongillies revised this gist
Aug 31, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,6 @@ function aws_config set -e AWS_SECRET_ACCESS_KEY set -e AWS_SESSION_TOKEN set account (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"account_id\") { print \$3 }}" ~/.aws/credentials) set username (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"username\") { print \$3 }}" ~/.aws/credentials) set mfarn "arn:aws:iam::$account:mfa/$username" -
davewongillies revised this gist
Aug 30, 2017 . 1 changed file with 37 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,20 +2,42 @@ function aws_config if not fgrep -q "[$argv]" ~/.aws/credentials echo "Please specify a valid profile." else set token_expired true if test $AWS_SESSION_EXPIRY set now (date +%s) set expiry (date -d $AWS_SESSION_EXPIRY +%s) if [ $now -lt $expiry ] echo "Token is still valid" set token_expired false else set -e AWS_SESSION_EXPIRY end end if [ $token_expired = true ] set -e AWS_ACCESS_KEY_ID set -e AWS_SECRET_ACCESS_KEY set -e AWS_SESSION_TOKEN # set -g -x ATLAS_TOKEN (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"atlas_token\") { print \$3 }}" ~/.aws/credentials) set account (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"account_id\") { print \$3 }}" ~/.aws/credentials) set username (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"username\") { print \$3 }}" ~/.aws/credentials) set mfarn "arn:aws:iam::$account:mfa/$username" set duration "43200" echo "Please enter your MFA token for $mfarn:" read -l mfa_token set aws_cli (aws --profile=$argv sts get-session-token \ --serial-number="$mfarn" \ --token-code=$mfa_token \ --duration-seconds $duration \ --output text \ --query \ 'Credentials | join (`;`,values({ AccessKeyId: join(``, [`set -Ux AWS_ACCESS_KEY_ID `,AccessKeyId]), SecretAccessKey:join(``, [`set -Ux AWS_SECRET_ACCESS_KEY `,SecretAccessKey]), SessionToken:join(``, [`set -Ux AWS_SESSION_TOKEN `,SessionToken]), Expiration:join(``, [`set -Ux AWS_SESSION_EXPIRY `,Expiration]) }))' ) fish -c $aws_cli end end end -
davewongillies revised this gist
Aug 30, 2017 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,17 +2,20 @@ function aws_config if not fgrep -q "[$argv]" ~/.aws/credentials echo "Please specify a valid profile." else set -e AWS_ACCESS_KEY_ID set -e AWS_SECRET_ACCESS_KEY set -e AWS_SESSION_TOKEN set -g -x ATLAS_TOKEN (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"atlas_token\") { print \$3 }}" ~/.aws/credentials) set account (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"account_id\") { print \$3 }}" ~/.aws/credentials) set username (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"username\") { print \$3 }}" ~/.aws/credentials) set mfarn "arn:aws:iam::$account:mfa/$username" echo "Please enter your MFA token:" read -l mfa_token set json (aws --profile=$argv sts get-session-token --serial-number="$mfarn" --token-code=$mfa_token) set -U -x AWS_ACCESS_KEY_ID (echo $json | jq -r '.Credentials.AccessKeyId') set -U -x AWS_SECRET_ACCESS_KEY (echo $json | jq -r '.Credentials.SecretAccessKey') set -U -x AWS_SESSION_TOKEN (echo $json | jq -r '.Credentials.SessionToken') set -U -x AWS_SESSION_EXPIRY (echo $json | jq -r '.Credentials.Expiration') end end -
mbainter revised this gist
Jun 9, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,6 @@ function aws_config set json (aws --profile=$argv sts get-session-token --serial-number="$mfarn" --token-code=$mfa_token) set -g -x AWS_ACCESS_KEY_ID (echo $json | jq -r '.Credentials.AccessKeyId') set -g -x AWS_SECRET_ACCESS_KEY (echo $json | jq -r '.Credentials.SecretAccessKey') set -g -x AWS_SESSION_TOKEN (echo $json | jq -r '.Credentials.SessionToken') end end -
mbainter created this gist
Jun 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ function aws_config if not fgrep -q "[$argv]" ~/.aws/credentials echo "Please specify a valid profile." else set -e AWS_ACCESS_KEY set -e AWS_SECRET_KEY set -g -x ATLAS_TOKEN (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"atlas_token\") { print \$3 }}" ~/.aws/credentials) set account (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"account_id\") { print \$3 }}" ~/.aws/credentials) set username (awk "/\[$argv\]/,/^\$/ { if (\$1 == \"username\") { print \$3 }}" ~/.aws/credentials) set mfarn "arn:aws:iam::$account:mfa/$username" echo "Please enter your MFA token:" read -l mfa_token set json (aws --profile=$argv sts get-session-token --serial-number="$mfarn" --token-code=$mfa_token) set -g -x AWS_ACCESS_KEY_ID (echo $json | jq -r '.Credentials.AccessKeyId') set -g -x AWS_SECRET_ACCESS_KEY (echo $json | jq -r '.Credentials.SecretAccessKey') set -g -x AWS_SECURITY_TOKEN (echo $json | jq -r '.Credentials.SessionToken') end end