commit
96c82fe460
|
|
@ -4,21 +4,17 @@ about-plugin 'AWS helper functions'
|
||||||
function awskeys {
|
function awskeys {
|
||||||
about 'helper function for AWS credentials file'
|
about 'helper function for AWS credentials file'
|
||||||
group 'aws'
|
group 'aws'
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then
|
||||||
__awskeys_help
|
|
||||||
elif [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then
|
|
||||||
__awskeys_list "$2"
|
__awskeys_list "$2"
|
||||||
elif [[ $# -eq 2 ]]; then
|
elif [[ $# -eq 1 ]] && [[ "$1" = "unset" ]]; then
|
||||||
if [[ "$1" = "show" ]]; then
|
__awskeys_unset "$2"
|
||||||
|
elif [[ $# -eq 2 ]] && [[ "$1" = "show" ]]; then
|
||||||
__awskeys_show "$2"
|
__awskeys_show "$2"
|
||||||
elif [[ "$1" = "export" ]]; then
|
elif [[ $# -eq 2 ]] && [[ "$1" = "export" ]]; then
|
||||||
__awskeys_export "$2"
|
__awskeys_export "$2"
|
||||||
else
|
else
|
||||||
__awskeys_help
|
__awskeys_help
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
__awskeys_help
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_help {
|
function __awskeys_help {
|
||||||
|
|
@ -26,9 +22,10 @@ function __awskeys_help {
|
||||||
echo -e "Helper to AWS credentials file.\n"
|
echo -e "Helper to AWS credentials file.\n"
|
||||||
echo -e "Commands:\n"
|
echo -e "Commands:\n"
|
||||||
echo " help Show this help message"
|
echo " help Show this help message"
|
||||||
echo " list List available credentials profiles"
|
echo " list List available AWS credentials profiles"
|
||||||
echo " show Show the keys associated to a credentials profile"
|
echo " show Show the AWS keys associated to a credentials profile"
|
||||||
echo " export Export a credentials profile keys as environment variables"
|
echo " export Export an AWS credentials profile keys as environment variables"
|
||||||
|
echo " unset Unset the AWS keys variables from the environment"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_get {
|
function __awskeys_get {
|
||||||
|
|
@ -39,7 +36,7 @@ function __awskeys_get {
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_list {
|
function __awskeys_list {
|
||||||
local credentials_list="$(egrep '^\[ *[a-zA-Z0-0_-]+ *\]$' ~/.aws/credentials)"
|
local credentials_list="$(egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials)"
|
||||||
if [[ -n $"{credentials_list}" ]]; then
|
if [[ -n $"{credentials_list}" ]]; then
|
||||||
echo -e "Available credentials profiles:\n"
|
echo -e "Available credentials profiles:\n"
|
||||||
for cred in ${credentials_list}; do
|
for cred in ${credentials_list}; do
|
||||||
|
|
@ -61,12 +58,18 @@ function __awskeys_show {
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_export {
|
function __awskeys_export {
|
||||||
local p_keys="$(__awskeys_get $1)"
|
local p_keys=( $(__awskeys_get $1 | tr -d " ") )
|
||||||
if [[ -n "${p_keys}" ]]; then
|
if [[ -n "${p_keys}" ]]; then
|
||||||
eval $(echo "${p_keys}" | tr -d " " | sed -r -e "s/(.+=)(.+)/export \U\1\E\2/")
|
for p_key in ${p_keys[@]}; do
|
||||||
|
local key="${p_key%=*}"
|
||||||
|
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
|
||||||
|
done
|
||||||
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"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __awskeys_unset {
|
||||||
|
unset AWS_DEFAULT_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue