Skip to content

Instantly share code, notes, and snippets.

@erkolson
Created May 27, 2020 03:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkolson/b75dbf48441d82409b79e91bc64b84be to your computer and use it in GitHub Desktop.
Save erkolson/b75dbf48441d82409b79e91bc64b84be to your computer and use it in GitHub Desktop.
gcloud shell access shortcuts
gcloudctx() {
context=$1
if [ -z "$context" ] ; then
echo "USAGE: gcloudctx <context-name>"
echo "Available contexts:"
gcloud config configurations list
elif gcloud config configurations list --format="value(Name)" | grep "^$context$" &>/dev/null; then
gcloud config configurations activate $context
else
echo "Creating context $context"
gcloud config configurations create $context
fi
}
# Troubleshoot access token
gcloud_app_default() {
TOKEN=$(gcloud auth application-default print-access-token)
curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=${TOKEN}"
}
gcloud_access_token(){
TOKEN=$(gcloud auth print-access-token)
curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=${TOKEN}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment