Created
December 9, 2021 23:13
-
-
Save evilmarty/f100035fe8ad57efb5460002eab0ce83 to your computer and use it in GitHub Desktop.
Check if your AWS SSO session is still valid and if not prompt a message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS_SSO_CACHE="${HOME}/.aws/sso/cache" | |
check_aws_sso_session() { | |
local files=() | |
if [ -d "$AWS_SSO_CACHE" ]; then | |
local files=("${AWS_SSO_CACHE}/*.json") | |
fi | |
for file in ${files[@]}; do | |
valid_cache "$file" && return 0 | |
done | |
/bin/cat <<EOT | |
AWS SSO session expired. Run the following to renew your session: | |
aws sso login | |
EOT | |
} | |
valid_cache() { | |
case "$1" in | |
*botocore-client-id*) | |
return 1 | |
;; | |
*) | |
/usr/local/bin/jq '.expiresAt | fromdate | if . > now then halt else halt_error end' "$1" 2>/dev/null | |
;; | |
esac | |
} | |
check_aws_sso_session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment