【问题标题】:Running gcloud test locally在本地运行 gcloud test
【发布时间】:2019-06-13 22:22:18
【问题描述】:

我有一个预提交挂钩设置来运行 Google Cloud Storage api 的测试套件。我可以模拟 Google Build 并很好地运行测试cloud-build-local --config=cloudbuild.yaml --dryrun=false .。但是,在运行预提交挂钩时,我收到错误

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

google_cloud_api.py 函数示例

def list_blobs(bucket_name):
    """Returns list of names of all the blobs in the bucket."""
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    blobs = bucket.list_blobs()
    return [blob.name for blob in blobs]

test_google_cloud_api.py 函数示例

def test_get_all_files():
    blobs = google_cloud_storage_api.list_blobs(GCS_BUCKET_NAME)
    for blob in blobs:
        print(blob)

【问题讨论】:

  • 如何运行预提交挂钩?
  • @CloudAce 通过使用pre-commit-config.yaml

标签: google-cloud-platform google-cloud-storage pytest google-cloud-build


【解决方案1】:

创建服务帐户并下载 json 文件,将 GOOGLE_APPLICATION_CREDENTIALS 设置为该文件

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json

或者使用

gcloud auth application-default login

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2018-07-16
    • 2021-08-30
    相关资源
    最近更新 更多