【发布时间】:2022-01-30 23:16:00
【问题描述】:
我正在尝试自动化一些 gsutils 命令,但很难查看身份验证文件的保存位置以及如何重复使用(如果发生这种情况)。
我已经完成了 bash 中的 gcloud init 进程...
curl https://sdk.cloud.google.com | bash
gcloud init
运行时一切正常
'gsutil ls'
现在我正在尝试自动化该过程,因此这将适用于添加到其上的 crontab 的新服务器(而不是每次都创建新配置)。
我看到提到设置 env 变量 GOOGLE_APPLICATION_CREDENTIALS,所以我将我的凭据从 Web 登录复制到一个文件并尝试了它,例如尝试以其他用户身份进行测试
export GOOGLE_APPLICATION_CREDENTIALS=/home/user/.gsutil/mycreds
然后是 gsutil ls,但是失败了。
所以我认为我的整个凭据有点错误。我假设某处有一个最初由 gcloud 创建的文件,我可以使用它,但我在任何地方都看不到它?
我已经查看了答案 here,但根据上次评论,现在似乎不是最新的。
编辑:我已按照 Zacharys 的步骤,gcloud auth activate-service-account --key-file=myfilelocation
但是,我现在得到了 'gsutil ls'..
You are attempting to perform an operation that requires a project id, with none configured. Please re-run gsutil config and make sure to follow the instructions for finding and entering your default project id.
所以我的下一个问题是,它在哪里寻找项目 ID?如果我运行 gsutil config,它似乎会创建一组新的身份验证,然后会产生另一个错误,因此已将其删除。
【问题讨论】:
-
gcloud 将其配置存储在 ~/.config/gcloud 中,因此,如果您有手动设置的有效安装,您至少应该能够将该配置复制到新服务器。不过,可能还有一种更优雅的方式。
-
谢谢,我可以在那里看到相关文件。
标签: google-cloud-storage gcloud