Fix verbs for recent storage change

1) Initialize the storage class in verbs with the extra needed args
2) Make the CloudFrontedS3Storage resilient to those extra args being missing
This commit is contained in:
Joseph Schorr 2017-10-07 00:11:44 -04:00
parent fba34eb5f0
commit f67e2baeba
2 changed files with 13 additions and 4 deletions

View file

@ -613,9 +613,15 @@ class CloudFrontedS3Storage(S3Storage):
def get_direct_download_url(self, path, request_ip=None, expires_in=60, requires_cors=False,
head=False):
# If CloudFront could not be loaded, fall back to normal S3.
if self.cloudfront_privatekey is None:
return super(CloudFrontedS3Storage, self).get_direct_download_url(path, request_ip,
expires_in, requires_cors,
head)
resolved_ip_info = None
logger.debug('Got direct download request for path "%s" with IP "%s"', path, request_ip)
if request_ip is not None:
if request_ip is not None and self._context.ip_resolver is not None:
# Lookup the IP address in our resolution table and determine whether it is under AWS. If it is,
# then return an S3 signed URL, since we are in-network.
resolved_ip_info = self._context.ip_resolver.resolve_ip(request_ip)
@ -652,6 +658,9 @@ class CloudFrontedS3Storage(S3Storage):
""" Returns the private key, loaded from the config provider, used to sign direct
download URLs to CloudFront.
"""
if self._context.config_provider is None:
return None
with self._context.config_provider.get_volume_file(cloudfront_privatekey_filename) as key_file:
return serialization.load_pem_private_key(
key_file.read(),