如何获得有效的经过身份验证的gcloud帐户? [英] How to get the active authenticated gcloud account?
问题描述
使用 gcloud auth ...
,您可以添加或删除在 gcloud
命令期间使用的帐户.
Using gcloud auth ...
you can add or remove accounts used during the gcloud
commands.
是否可以在没有 grep
-ing和 awk
-ing的情况下获得活动帐户?
Is there a way to get the active account without grep
-ing and awk
-ing?
gcloud身份验证列表
对人类有益,但对机器而言却不够好.我想要一个更清洁的解决方案.
gcloud auth list
is good for humans but not good enough to a machine. I want a cleaner solution.
gcloud配置列表帐户
还向我显示了详细的输出:
gcloud config list account
also shows me to verbose output:
Your active configuration is: [default]
[core]
account = service@<my_project>.iam.gserviceaccount.com
推荐答案
我找到了解决方法:
gcloud config list account --format "value(core.account)"
这会告诉你:
Your active configuration is: [default]
service@<my_project>.iam.gserviceaccount.com
为了避免出现活动配置消息,您可以将stderr重定向到/dev/null
:
To also avoid the active configuration message, you can redirect the stderr to /dev/null
:
$ gcloud config list account --format "value(core.account)" 2> /dev/null
service@<my_project>.iam.gserviceaccount.com
如果-verbosity
在这种情况下也可以删除 info
消息,那将很好.那将意味着:
It would be nice if --verbosity
would also work in this case to remove the info
message. That would mean:
$ gcloud config list account --format "value(core.account)" --verbosity error
如果这是合理的功能/错误请求/报告,有没有Google员工可以发表评论?
Any Googlers out there that can post a comment if this is a reasonable feature/bug request/report?
这篇关于如何获得有效的经过身份验证的gcloud帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!