Запуск теста gcloud локально - PullRequest
0 голосов
/ 14 июня 2019

У меня есть предварительная настройка ловушки для запуска набора тестов для API Google Cloud Storage.Я могу смоделировать 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

Sample google_cloud_api.py function

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]

Sample test_google_cloud_api.py function

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

1 Ответ

2 голосов
/ 14 июня 2019

Создайте учетную запись службы и загрузите файл json, установите для этого файла GOOGLE_APPLICATION_CREDENTIALS

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

Или используйте

gcloud auth application-default login
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...