问题
In order not to call every time:
gcloud auth login
which would interrupt a script for user input
I would like to see if a user is already authenticated (any user) and only if no user, then to call gcloud auth login
.
I would love a more elegant/reliable solution than scraping the output of gcloud auth list
. Something like a ping
that fails or succeeds if there is an account already AND the account has the right to do the thing. Maybe a --dry-run
option?
回答1:
Being logged in means having account property set. You can extract it via
gcloud config list --format='value(core.account)' 2>/dev/null
You can also use
gcloud auth list --format='value(active_account)' 2>/dev/null
来源:https://stackoverflow.com/questions/35173114/how-can-i-check-if-a-google-vm-instance-has-already-credentials-for-gcloud