Skip to content

Commit

Permalink
[s3] fix disabling cloudfront signing with class variable (#1334)
Browse files Browse the repository at this point in the history
This change fixes setting ``cloudfront_signer=None`` as a class variable
to disable cloudfront signing (or passing a custom implementation), and
is a follow up to #1326
  • Loading branch information
terencehonles committed Nov 23, 2023
1 parent d0dce62 commit 1a22b32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion storages/backends/s3.py
Expand Up @@ -300,7 +300,8 @@ class S3Storage(CompressStorageMixin, BaseStorage):

def __init__(self, **settings):
omitted = object()
self.cloudfront_signer = settings.pop("cloudfront_signer", omitted)
if not hasattr(self, "cloudfront_signer"):
self.cloudfront_signer = settings.pop("cloudfront_signer", omitted)

super().__init__(**settings)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_s3.py
Expand Up @@ -894,6 +894,12 @@ def test_cloudfront_config(self):
storage = s3.S3Storage(cloudfront_signer=None)
self.assertIsNone(storage.cloudfront_signer)

# allow disabling cloudfront signing in subclass
class Storage(s3.S3Storage):
cloudfront_signer = None

self.assertIsNone(Storage().cloudfront_signer)

storage = s3.S3Storage(cloudfront_key_id=key_id, cloudfront_key=pem)
self.assertIsNotNone(storage.cloudfront_signer)

Expand Down

0 comments on commit 1a22b32

Please sign in to comment.