Allow custom aws config files path
Honor the environment variables: AWS_CONFIG_FILE AWS_SHARED_CREDENTIALS_FILE in the aws plugin. +info: https://docs.aws.amazon.com/cli/latest/userguide/cli-environment.htmlpull/1258/head
parent
73af202a32
commit
3c8dbf3cd4
|
|
@ -1,11 +1,14 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'AWS helper functions'
|
about-plugin 'AWS helper functions'
|
||||||
|
|
||||||
|
AWS_CONFIG_FILE="${AWS_CONFIG_FILE:-$HOME/.aws/config}"
|
||||||
|
AWS_SHARED_CREDENTIALS_FILE="${AWS_SHARED_CREDENTIALS_FILE:-$HOME/.aws/credentials}"
|
||||||
|
|
||||||
function awskeys {
|
function awskeys {
|
||||||
about 'helper function for AWS credentials file'
|
about 'helper function for AWS credentials file'
|
||||||
group 'aws'
|
group 'aws'
|
||||||
|
|
||||||
if [[ ! -f ~/.aws/credentials ]]; then
|
if [[ ! -f "${AWS_SHARED_CREDENTIALS_FILE}" ]]; then
|
||||||
echo "AWS credentials file not found"
|
echo "AWS credentials file not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -35,14 +38,14 @@ function __awskeys_help {
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_get {
|
function __awskeys_get {
|
||||||
local ln=$(grep -n "\[ *$1 *\]" ~/.aws/credentials | cut -d ":" -f 1)
|
local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)
|
||||||
if [[ -n "${ln}" ]]; then
|
if [[ -n "${ln}" ]]; then
|
||||||
tail -n +${ln} ~/.aws/credentials | egrep -m 3 "aws_access_key_id|aws_secret_access_key|aws_session_token"
|
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 3 "aws_access_key_id|aws_secret_access_key|aws_session_token"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __awskeys_list {
|
function __awskeys_list {
|
||||||
local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials; grep "\[profile" ~/.aws/config | sed "s|\[profile |\[|g") | sort | uniq)"
|
local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue