Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easy to customise expiration for cloudfront #1226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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