【问题标题】:Can I pass a key file as parameter to connect to Google Cloud Storage using gsutil?我可以将密钥文件作为参数传递以使用 gsutil 连接到 Google Cloud Storage 吗?
【发布时间】:2020-11-12 23:41:48
【问题描述】:

当我使用gsutil 连接到我在 Google Cloud Storage 上的存储桶时,我通常使用以下命令:

gcloud auth activate-service-account --key-file="pathKeyFile"

如果同时在同一台机器上运行的两个脚本需要两个不同的服务帐户,我该怎么办?

我想使用如下命令:

gsutil ls mybucket --key-file="mykeyspath"

我这样说是因为如果我的脚本正在运行并且另一个脚本更改了实际处于活动状态的服务帐户,我的脚本将不再有权访问存储桶。

【问题讨论】:

    标签: authentication google-cloud-platform google-cloud-storage service-accounts gsutil


    【解决方案1】:

    您可以使用BOTO file 执行此操作。您可以创建一个as explained in the documentation

    然后您可以指定在运行 gsutil 命令时使用哪个文件(这里是 linux 中的示例)

    # if you have several GSUTIL command to run
    export BOTO_CONFIG=/path/to/.botoMyBucket
    gsutil ls myBucket
    
    # For only one command, you can define an env var inline like this
    BOTO_CONFIG=/path/to/.botoMyBucket2 gsutil ls myBucket2
    

    【讨论】:

    • 我遵循第一个建议。非常感谢,它有效!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2015-11-14
    • 1970-01-01
    • 2015-12-29
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多