From 1a22b32220e381c1f3fced06192f729733d00dc8 Mon Sep 17 00:00:00 2001 From: Terence Honles Date: Thu, 23 Nov 2023 09:39:09 -0800 Subject: [PATCH] [s3] fix disabling cloudfront signing with class variable (#1334) 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 https://github.com/jschneier/django-storages/pull/1326 --- storages/backends/s3.py | 3 ++- tests/test_s3.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/storages/backends/s3.py b/storages/backends/s3.py index 466489c8..0cc1c096 100644 --- a/storages/backends/s3.py +++ b/storages/backends/s3.py @@ -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) diff --git a/tests/test_s3.py b/tests/test_s3.py index 36f75b32..30bf903e 100644 --- a/tests/test_s3.py +++ b/tests/test_s3.py @@ -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)