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 Mar 28, 2023
1 parent 90e2e78 commit ec64e58
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit ec64e58

Please sign in to comment.