Skip to content

Commit

Permalink
Include gcloud storage backend automatically (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Apr 20, 2022
1 parent ac6d194 commit 77a181a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
6.3.0 (unreleased)
------------------

- Nothing changed yet.
**New features**

- Include the Google Cloud backend automatically when ``kinto.attachment.gcloud.*`` settings are used.


6.2.0 (2021-12-02)
Expand Down
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ Store on Amazon S3:
See `Pyramid Storage <https://pythonhosted.org/pyramid_storage/>`_.


Google Cloud Storage
--------------------

.. code-block:: ini
kinto.attachment.gcloud.credentials = <Path to the Service Accounts credentials JSON file>
kinto.attachment.gcloud.bucket_name = <bucket name>
kinto.attachment.gcloud.acl = publicRead
See `Google Cloud ACL permissions <https://cloud.google.com/storage/docs/access-control/making-data-public>`_


The ``folder`` option
---------------------

Expand Down
2 changes: 2 additions & 0 deletions kinto_attachment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def includeme(config):
# Enable attachment backend.
if 'storage.base_path' in storage_settings:
config.include('pyramid_storage.local')
elif 'storage.gcloud.credentials' in storage_settings:
config.include('pyramid_storage.gcloud')
else:
config.include('pyramid_storage.s3')

Expand Down
17 changes: 17 additions & 0 deletions kinto_attachment/tests/test_plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from pyramid import testing
from pyramid.exceptions import ConfigurationError
from pyramid_storage.interfaces import IFileStorage
from pyramid_storage.s3 import S3FileStorage
from pyramid_storage.gcloud import GoogleCloudStorage
from kinto import main as kinto_main
from kinto_attachment import __version__, includeme

Expand Down Expand Up @@ -58,3 +61,17 @@ def test_base_url_is_added_a_trailing_slash(self):
"attachment.base_url": "http://cdn.com",
})
assert config.registry.api_capabilities["attachments"]["base_url"] == "http://cdn.com/"

def test_gcloud_is_used_if_credentials_setting_is_used(self):
config = self.includeme(settings={
"attachment.gcloud.credentials": "/path/to/credentials.json",
"attachment.gcloud.bucket_name": "foo",
})
assert isinstance(config.registry.queryUtility(IFileStorage), GoogleCloudStorage)

def test_s3_is_used_if_base_path_setting_is_not_used(self):
config = self.includeme(settings={
"attachment.aws.access_key": "abc",
"attachment.aws.bucket_name": "foo",
})
assert isinstance(config.registry.queryUtility(IFileStorage), S3FileStorage)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

requirements = [
'boto',
'google-cloud-storage',
'kinto<15', # content-type header in delete responses
'pyramid_storage>=0.1.0',
]
Expand Down

0 comments on commit 77a181a

Please sign in to comment.