Skip to content

Commit

Permalink
Make it easy to customise expiration for cloudfront
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogost committed Sep 5, 2023
1 parent cb8b810 commit cfb0c58
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion storages/backends/s3.py
Expand Up @@ -570,6 +570,9 @@ def _strip_signing_parameters(self, url):
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.
name = self._normalize_name(clean_name(name))
Expand All @@ -586,7 +589,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
Expand Down

0 comments on commit cfb0c58

Please sign in to comment.