Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
fix: gcloud credentials as env var
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 3, 2019
1 parent ee90b0c commit 2f8ad5f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
/static_root/
/build/
dist/
aws-credentials
storage-credentials
.mypy_cache
.idea
.python-version
gcloud-credentials.json
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SHELL := /usr/bin/env bash

test:
. aws-credentials && ./runtests.py
. storage-credentials && ./runtests.py

test-coverage:
. aws-credentials && coverage run --source collectfast ./runtests.py
. storage-credentials && coverage run --source collectfast ./runtests.py

distribute:
pip install --upgrade wheel twine setuptools
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ open and welcome.

The test suite is built to run against an S3 bucket. To be able to test locally
you need to provide AWS credentials for a bucket to test against. Add the
credentials to a file named `aws-credentials` in the root of the project
credentials to a file named `storage-credentials` in the root of the project
directory:

.. code:: bash
Expand Down
14 changes: 11 additions & 3 deletions collectfast/tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import tempfile

from google.oauth2 import service_account

Expand Down Expand Up @@ -45,7 +46,14 @@
AWS_S3_HOST = "s3.eu-central-1.amazonaws.com"

# Google Cloud
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
str(base_path / "gcloud-credentials.json")
)
gcloud_credentials_json = os.environ.get('GCLOUD_CREDENTIALS', "").strip()
if not gcloud_credentials_json:
GS_CREDENTIALS = None
else:
with tempfile.NamedTemporaryFile() as file:
file.write(gcloud_credentials_json.encode())
file.read()
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
file.name
)
GS_BUCKET_NAME = "roasted-dufus"

0 comments on commit 2f8ad5f

Please sign in to comment.