From ec64e5821ab498c5b1aaccc1844c0a70e02c21ce Mon Sep 17 00:00:00 2001 From: Alexandr Artemyev Date: Tue, 28 Mar 2023 15:16:31 +0600 Subject: [PATCH] Make it easy to customise expiration for cloudfront --- storages/backends/s3boto3.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/storages/backends/s3boto3.py b/storages/backends/s3boto3.py index 7231750f4..8e5ff2f00 100644 --- a/storages/backends/s3boto3.py +++ b/storages/backends/s3boto3.py @@ -561,6 +561,9 @@ def _strip_signing_parameters(self, url): joined_qs = ('='.join(keyval) for keyval in filtered_qs) split_url = split_url._replace(query='&'.join(joined_qs)) return split_url.geturl() + + def _get_expiration_for_cloudfront(self, expire): + return datetime.utcnow() + timedelta(seconds=expire) def url(self, name, parameters=None, expire=None, http_method=None): # Preserve the trailing slash after normalizing the path. @@ -578,7 +581,7 @@ def url(self, name, parameters=None, expire=None, http_method=None): ) if self.querystring_auth and self.cloudfront_signer: - expiration = datetime.utcnow() + timedelta(seconds=expire) + expiration = self._get_expiration_for_cloudfront(expire) return self.cloudfront_signer.generate_presigned_url(url, date_less_than=expiration) return url