Skip to content

Instantly share code, notes, and snippets.

@hartror
Created March 4, 2018 09:51
Show Gist options
  • Save hartror/081567878adf58b3f553f29f22ec6c77 to your computer and use it in GitHub Desktop.
Save hartror/081567878adf58b3f553f29f22ec6c77 to your computer and use it in GitHub Desktop.
A minimal translation of the awsume bash file for the fish shell.
#!/usr/bin/env fish
function awsume
set AWS_VARS "AWS_SECRET_ACCESS_KEY" "AWS_SESSION_TOKEN" "AWS_SECURITY_TOKEN" "AWS_ACCESS_KEY_ID" "AWS_REGION" "AWS_DEFAULT_REGION" "AWS_PROFILE" "AWS_DEFAULT_PROFILE" "AWSUME_PROFILE"
set AWSUME (string split " " (awsumepy))
set AWSUME_FLAG "$AWSUME[1]"
if test $AWSUME_FLAG = "usage:"
awsumepy -h
else if test $AWSUME_FLAG = "Version"
awsumepy -v
else if test $AWSUME_FLAG = "Listing..."
awsumepy -l
else if test $AWSUME_FLAG = "Auto"
for var in $AWS_VARS
set -e $var
end
set -gx AWS_PROFILE $AWSUME_FLAG[2]
set -gx AWS_DEFAULT_PROFILE $AWSUME_FLAG[2]
set -gx AWSUME_PROFILE $AWSUME_FLAG[3]
#TODO
#run the background autoAwsume process
#autoAwsume & disown
else if test $AWSUME_FLAG = "Kill"
for var in $AWS_VARS
set -e $var
end
else if test $AWSUME_FLAG = "Stop"
if test "auto-refesh-$AWSUME[2]" = "$AWS_PROFILE"
set -e AWS_PROFILE
set -e AWS_DEFAULT_PROFILE
end
else if test "$AWSUME_FLAG" = "Awsume"
for var in $AWS_VARS
set -e $var
end
set -gx AWS_ACCESS_KEY_ID $AWSUME[2]
set -gx AWS_SECRET_ACCESS_KEY $AWSUME[3]
if test "$AWSUME[4]" != "None"
set -gx AWS_SESSION_TOKEN $AWSUME[4]
set -gx AWS_SECURITY_TOKEN $AWSUME[4]
end
if test "$AWSUME[4]" != "None"
set -gx AWS_REGION $AWSUME[5]
set -gx AWS_DEFAULT_REGION $AWSUME[5]
end
#TODO
#if enabled, show the exact commands to use in order to assume the role we just assumed
#<insert code here>
set -gx AWSUME_PROFILE $AWSUME[6]
end
end
@matt-whiteley
Copy link

This was very helpful. I will point out this doesn't pass any params to awsumepy so line 6 needs changing to set AWSUME (string split " " (awsumepy $argv)) to enable changing to other profiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment