allow HEAD on ACI images

Fixes #911.
This commit is contained in:
Jimmy Zelinskie 2016-02-11 17:00:38 -05:00
parent a9c64545fa
commit 2b07b6d8a9
5 changed files with 11 additions and 7 deletions

View file

@ -258,7 +258,9 @@ def _repo_verb(namespace, repository, tag, verb, formatter, sign=False, checker=
if not derived.uploading: if not derived.uploading:
logger.debug('Derived %s image %s exists in storage', verb, derived.uuid) logger.debug('Derived %s image %s exists in storage', verb, derived.uuid)
derived_layer_path = model.storage.get_layer_path(derived) derived_layer_path = model.storage.get_layer_path(derived)
download_url = storage.get_direct_download_url(derived.locations, derived_layer_path) is_head_request = request.method == 'HEAD'
download_url = storage.get_direct_download_url(derived.locations, derived_layer_path,
head=is_head_request)
if download_url: if download_url:
logger.debug('Redirecting to download URL for derived %s image %s', verb, derived.uuid) logger.debug('Redirecting to download URL for derived %s image %s', verb, derived.uuid)
return redirect(download_url) return redirect(download_url)
@ -359,7 +361,7 @@ def get_aci_signature(server, namespace, repository, tag, os, arch):
@anon_protect @anon_protect
@verbs.route('/aci/<server>/<namespace>/<repository>/<tag>/aci/<os>/<arch>/', methods=['GET']) @verbs.route('/aci/<server>/<namespace>/<repository>/<tag>/aci/<os>/<arch>/', methods=['GET', 'HEAD'])
@process_auth @process_auth
def get_aci_image(server, namespace, repository, tag, os, arch): def get_aci_image(server, namespace, repository, tag, os, arch):
return _repo_verb(namespace, repository, tag, 'aci', ACIImage(), return _repo_verb(namespace, repository, tag, 'aci', ACIImage(),

View file

@ -46,7 +46,7 @@ class BaseStorage(StoragePaths):
client to use for any external calls. """ client to use for any external calls. """
pass pass
def get_direct_download_url(self, path, expires_in=60, requires_cors=False): def get_direct_download_url(self, path, expires_in=60, requires_cors=False, head=False):
return None return None
def get_direct_upload_url(self, path, mime_type, requires_cors=True): def get_direct_upload_url(self, path, mime_type, requires_cors=True):

View file

@ -116,10 +116,12 @@ class _CloudStorage(BaseStorageV2):
def get_supports_resumable_downloads(self): def get_supports_resumable_downloads(self):
return True return True
def get_direct_download_url(self, path, expires_in=60, requires_cors=False): def get_direct_download_url(self, path, expires_in=60, requires_cors=False, head=False):
self._initialize_cloud_conn() self._initialize_cloud_conn()
path = self._init_path(path) path = self._init_path(path)
k = self._key_class(self._cloud_bucket, path) k = self._key_class(self._cloud_bucket, path)
if head:
return k.generate_url(expires_in, 'HEAD')
return k.generate_url(expires_in) return k.generate_url(expires_in)
def get_direct_upload_url(self, path, mime_type, requires_cors=True): def get_direct_upload_url(self, path, mime_type, requires_cors=True):

View file

@ -15,7 +15,7 @@ class FakeStorage(BaseStorageV2):
def _init_path(self, path=None, create=False): def _init_path(self, path=None, create=False):
return path return path
def get_direct_download_url(self, path, expires_in=60, requires_cors=False): def get_direct_download_url(self, path, expires_in=60, requires_cors=False, head=False):
try: try:
if self.get_content('supports_direct_download') == 'true': if self.get_content('supports_direct_download') == 'true':
return 'http://somefakeurl' return 'http://somefakeurl'

View file

@ -114,7 +114,7 @@ class SwiftStorage(BaseStorage):
logger.exception('Could not head object: %s', path) logger.exception('Could not head object: %s', path)
return None return None
def get_direct_download_url(self, object_path, expires_in=60, requires_cors=False): def get_direct_download_url(self, object_path, expires_in=60, requires_cors=False, head=False):
if requires_cors: if requires_cors:
return None return None
@ -137,7 +137,7 @@ class SwiftStorage(BaseStorage):
object_path = self._normalize_path(object_path) object_path = self._normalize_path(object_path)
# Generate the signed HMAC body. # Generate the signed HMAC body.
method = 'GET' method = 'HEAD' if head else 'GET'
expires = int(time() + expires_in) expires = int(time() + expires_in)
full_path = '%s/%s/%s' % (path, self._swift_container, object_path) full_path = '%s/%s/%s' % (path, self._swift_container, object_path)