如何获取有效的经过身份验证的 gcloud 帐户? [英] How to get the active authenticated gcloud account?

查看:23
本文介绍了如何获取有效的经过身份验证的 gcloud 帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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 auth list 对人类有好处,但对机器来说还不够好.我想要一个更简洁的解决方案.

gcloud auth list is good for humans but not good enough to a machine. I want a cleaner solution.

gcloud config list account 还向我展示了详细的输出:

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

为了避免主动配置消息,您可以将标准错误重定向到/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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆