Skip to content

Instantly share code, notes, and snippets.

@vevetron
Last active August 11, 2025 16:11
Show Gist options
  • Select an option

  • Save vevetron/e04f74c4e55d13d5144f8207b1677e2d to your computer and use it in GitHub Desktop.

Select an option

Save vevetron/e04f74c4e55d13d5144f8207b1677e2d to your computer and use it in GitHub Desktop.
Caltrans bash profile
# Add this to your .bash_profile. Also put a copy of the login.json in your home directory at ~/iac/login.json
#
source ~/.profile
# --- gcloud auto-login check ---
# Commands to revoke any existing logins
# gcloud auth revoke --all
# gcloud auth application-default revoke
# An alias to run application-default login
alias glogin='gcloud auth application-default login --login-config=$HOME/iac/login.json'
alias oglogin='gcloud auth login --login-config=$HOME/iac/login.json'
_GCLOUD_LOGIN_CONFIG="$HOME/iac/login.json"
_GCLOUD_LOGIN_ATTEMPTED=false
# Check Application Default Credentials (ADC)
# Check ADC independently, as it might expire separately or fail for other reasons
if ! gcloud auth application-default print-access-token --quiet >/dev/null 2>&1; then
echo "[Bash Profile] gcloud ADC token check failed. Attempting login..."
gcloud auth application-default login --login-config="$_GCLOUD_LOGIN_CONFIG" --quiet
if [ $? -ne 0 ]; then
echo "[Bash Profile] gcloud auth application-default login failed." >&2
else
_GCLOUD_LOGIN_ATTEMPTED=true
fi
fi
# Clean up temporary variables
unset _GCLOUD_LOGIN_CONFIG _GCLOUD_LOGIN_ATTEMPTED
# --- end gcloud auto-login check ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment