Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7 Add support for session expiration #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions get-aws-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ echo_stderr() {

display_usage ()
{
echo_stderr "Usage: $0 [--credentials=<path>] [--profile=<name>] [--key|--secret|--session-token]"
echo_stderr "Usage: $0 [--credentials=<path>] [--profile=<name>] [--key|--secret|--session-token|--session-expiration]"
echo_stderr " Default --credentials is '~/.aws/credentials'"
echo_stderr " Default --profile is 'default'"
echo_stderr " By default environment variables are generate, e.g."
echo_stderr " source \$($0 --profile=myprofile)"
echo_stderr " You can specify one of --key, --secret, -or --session-token to get just that value, with no line break,"
echo_stderr " You can specify one of --key, --secret, --session-token or --session-expiration to get just that value, with no line break,"
echo_stderr " FOO_KEY=\$($0 --profile=myprofile --key)"
echo_stderr " FOO_SECRET=\$($0 --profile=myprofile --secret)"
echo_stderr " FOO_SESSION_TOKEN=\$($0 --profile=myprofile --session-token)"
echo_stderr " FOO_SESSION_EXPIRATION=\$($0 --profile=myprofile --session-expiration)"
}

for i in "$@"
do
case $i in
case $i in
--credentials=*)
CREDENTIALS="${i#*=}"
shift # past argument=value
Expand All @@ -83,6 +84,10 @@ case $i in
SHOW_SESSION_TOKEN=true
shift # past argument with no value
;;
--session-expiration)
SHOW_SESSION_EXPIRATION=true
shift # past argument with no value
;;
--help)
display_usage
exit 0
Expand All @@ -93,7 +98,7 @@ case $i in
display_usage
exit 1
;;
esac
esac
done

#
Expand All @@ -105,6 +110,7 @@ PROFILE=${PROFILE:-default}
SHOW_KEY=${SHOW_KEY:-false}
SHOW_SECRET=${SHOW_SECRET:-false}
SHOW_SESSION_TOKEN=${SHOW_SESSION_TOKEN:-false}
SHOW_SESSION_EXPIRATION=${SHOW_SESSION_EXPIRATION:-false}

if [[ "${SHOW_KEY}" = true && "${SHOW_SECRET}" = true ]]; then
echo_stderr "Can only specify one of --key or --secret"
Expand Down Expand Up @@ -133,16 +139,19 @@ if [[ $? -ne 0 ]]; then
exit 5
fi

if [[ "${SHOW_KEY}" = false && "${SHOW_SECRET}" = false && "${SHOW_SESSION_TOKEN}" = false ]]; then
if [[ "${SHOW_KEY}" = false && "${SHOW_SECRET}" = false && "${SHOW_SESSION_TOKEN}" = false && "${SHOW_EXPIRATION}" = false ]]; then
Copy link

@virgilwashere virgilwashere Jul 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$SHOW_EXPIRATION is probably meant to be $SHOW_SESSION_EXPIRATION

echo "export AWS_ACCESS_KEY_ID=${aws_access_key_id}"
echo "export AWS_SECRET_ACCESS_KEY=${aws_secret_access_key}"
echo "export AWS_SESSION_TOKEN=${aws_session_token}"
echo "export AWS_SESSION_EXPIRATION=${aws_session_expiration}"
elif [[ "${SHOW_KEY}" = true ]]; then
echo -n "${aws_access_key_id}"
elif [[ "${SHOW_SECRET}" = true ]]; then
echo -n "${aws_secret_access_key}"
elif [[ "${SHOW_SESSION_TOKEN}" = true ]]; then
echo -n "${aws_session_token}"
elif [[ "${SHOW_SESSION_EXPIRATION}" = true ]]; then
echo -n "${aws_session_expiration}"
else
echo_stderr "Unknown error"
exit 9
Expand Down