awsprofile

renamed awslogin to awsprofile
added pattern match
This commit is contained in:
Andrea Mistrali 2021-10-27 11:02:09 +02:00
parent 4166f55fd4
commit 3d9237d5ce
No known key found for this signature in database
GPG Key ID: 6FB0A77F6D5DA9B2
4 changed files with 30 additions and 22 deletions

View File

@ -1,22 +0,0 @@
profile=$1
if [ $profile ]; then
match=$(grep $profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/')
if [ $match ]; then
echo "Activating $match"
export AWS_DEFAULT_PROFILE=$match
export AWS_PROFILE=$match
export AWS_EB_PROFILE=$match
return
else
echo "No match for $profile"
return
fi
elif [ $AWS_PROFILE ]; then
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE
echo AWS profile cleared.
return
fi
echo "Available profiles"
grep profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/'

Binary file not shown.

View File

@ -0,0 +1,30 @@
profile=$1
if [ $profile ]; then # We got a profile pattern, look for a match
match=$(grep -E "\[profile .*$profile.*" ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/')
match_no=$(echo $match|wc -l)
if [ $match_no -gt 1 ]; then # more than one match
echo "Multiple matches:"
echo $match
return
fi
if [ $match ]; then # Single match, setting profile
echo "Activating $match"
export AWS_DEFAULT_PROFILE=$match
export AWS_PROFILE=$match
export AWS_EB_PROFILE=$match
return
else
echo "No match for $profile"
return
fi
elif [ $AWS_PROFILE ]; then # no profile passed, clean up current one, logout
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE
echo profile cleared.
return
fi
echo "Available profiles"
grep profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/'
# vim: set ts=2 sw=2 tw=0 ft=sh :

Binary file not shown.