Merge pull request #1070 from padilo/awskeys-fix-profile-list

fixed awskeys with all profiles
pull/1075/head
Nils Winkler 2017-10-28 14:33:23 +02:00 committed by GitHub
commit 51fb2c86ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -42,7 +42,7 @@ function __awskeys_get {
} }
function __awskeys_list { function __awskeys_list {
local credentials_list="$(egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials)" local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials; grep "\[profile" ~/.aws/config | sed "s|\[profile |\[|g") | sort | uniq)"
if [[ -n $"{credentials_list}" ]]; then if [[ -n $"{credentials_list}" ]]; then
echo -e "Available credentials profiles:\n" echo -e "Available credentials profiles:\n"
for profile in ${credentials_list}; do for profile in ${credentials_list}; do
@ -64,12 +64,14 @@ function __awskeys_show {
} }
function __awskeys_export { function __awskeys_export {
if [[ $(__awskeys_list) == *"$1"* ]]; then
local p_keys=( $(__awskeys_get $1 | tr -d " ") ) local p_keys=( $(__awskeys_get $1 | tr -d " ") )
if [[ -n "${p_keys}" ]]; then if [[ -n "${p_keys}" ]]; then
for p_key in ${p_keys[@]}; do for p_key in ${p_keys[@]}; do
local key="${p_key%=*}" local key="${p_key%=*}"
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}" export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
done done
fi
export AWS_DEFAULT_PROFILE="$1" export AWS_DEFAULT_PROFILE="$1"
else else
echo "Profile $1 not found in credentials file" echo "Profile $1 not found in credentials file"