How can I check if a Google VM instance has already credentials for gcloud

孤街浪徒 提交于 2019-12-11 00:59:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!