Skip to content

Commit 91ddf03

Browse files
authored
Merge pull request #79 from risQinc/make_google_credentials_file_optional
make JSON_CREDENTIALS optional
2 parents 9b791f1 + 639ba22 commit 91ddf03

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,14 @@ by `django-distill` are:
478478
'some-google-storage-bucket': {
479479
'ENGINE': 'django_distill.backends.google_storage',
480480
'PUBLIC_URL': 'https://storage.googleapis.com/[bucket.name.here]/',
481-
'JSON_CREDENTIALS': '/path/to/some/credentials.json',
482481
'BUCKET': '[bucket.name.here]',
482+
'JSON_CREDENTIALS': '/path/to/some/credentials.json',
483483
},
484484
```
485485

486+
Note that `JSON_CREDENTIALS` is optional; if it is not specified, the google libraries will try other authentication methods, in the search order described here: https://cloud.google.com/docs/authentication/application-default-credentials (e.g. the GOOGLE_APPLICATION_CREDENTIALS environment variable, an attached service account, etc).
487+
488+
486489
**django_distill.backends.microsoft_azure_storage**: Publish to a Microsoft
487490
Azure Blob Storage container. Requires the Python library
488491
`azure-storage-blob` (`$ pip install django-distill[microsoft]`). The storage

django_distill/backends/google_storage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GoogleCloudStorageBackend(BackendBase):
2525
Publisher for Google Cloud Storage. Implements the BackendBase.
2626
'''
2727

28-
REQUIRED_OPTIONS = ('ENGINE', 'JSON_CREDENTIALS', 'BUCKET')
28+
REQUIRED_OPTIONS = ('ENGINE', 'BUCKET')
2929

3030
def account_username(self):
3131
return
@@ -35,10 +35,12 @@ def account_container(self):
3535

3636
def authenticate(self):
3737
credentials_file = self.options.get('JSON_CREDENTIALS', '')
38-
if not os.path.exists(credentials_file):
39-
err = 'Credentials file does not exist: {}'
40-
raise DistillPublishError(err.format(credentials_file))
41-
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_file
38+
if credentials_file:
39+
if not os.path.exists(credentials_file):
40+
err = 'Credentials file does not exist: {}'
41+
raise DistillPublishError(err.format(credentials_file))
42+
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_file
43+
4244
bucket = self.account_container()
4345
self.d['connection'] = storage.Client()
4446
self.d['bucket'] = self.d['connection'].get_bucket(bucket)

0 commit comments

Comments
 (0)