Last active
August 11, 2025 16:11
-
-
Save vevetron/e04f74c4e55d13d5144f8207b1677e2d to your computer and use it in GitHub Desktop.
Caltrans bash profile
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
| # 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