Add request IP to get_direct_download_url method

This commit is contained in:
Joseph Schorr 2017-09-25 17:14:28 -04:00
parent ad61df66c5
commit 56fbbcf7cf
8 changed files with 13 additions and 11 deletions

View file

@ -107,7 +107,8 @@ class DelegateUserfiles(object):
def get_file_url(self, file_id, expires_in=300, requires_cors=False):
path = self.get_file_id_path(file_id)
url = self._storage.get_direct_download_url(self._locations, path, expires_in, requires_cors)
url = self._storage.get_direct_download_url(self._locations, path, request.remote_addr, expires_in,
requires_cors)
if url is None:
if self._handler_name is None:

View file

@ -6,6 +6,7 @@ from cnr.models.channel_base import ChannelBase
from cnr.models.db_base import CnrDB
from cnr.models.package_base import PackageBase, manifest_media_type
from flask import request
from app import storage
from endpoints.appr.models_oci import model
@ -36,7 +37,7 @@ class Blob(BlobBase):
locations = model.get_blob_locations(digest)
if not locations:
raise_package_not_found(package_name, digest)
return storage.get_direct_download_url(locations, blobpath)
return storage.get_direct_download_url(locations, blobpath, request.remote_addr)
class Channel(ChannelBase):

View file

@ -132,7 +132,7 @@ def get_image_layer(namespace, repository, image_id, headers):
abort(404, 'Image %(image_id)s not found', issue='unknown-image', image_id=image_id)
try:
logger.debug('Looking up the direct download URL for path: %s', path)
direct_download_url = store.get_direct_download_url(locations, path)
direct_download_url = store.get_direct_download_url(locations, path, request.remote_addr)
if direct_download_url:
logger.debug('Returning direct download URL')
resp = redirect(direct_download_url)

View file

@ -83,7 +83,7 @@ def download_blob(namespace_name, repo_name, digest):
# Short-circuit by redirecting if the storage supports it.
logger.debug('Looking up the direct download URL for path: %s', path)
direct_download_url = storage.get_direct_download_url(blob.locations, path)
direct_download_url = storage.get_direct_download_url(blob.locations, path, request.remote_addr)
if direct_download_url:
logger.debug('Returning direct download URL')
resp = redirect(direct_download_url)

View file

@ -119,7 +119,7 @@ class _CloudStorage(BaseStorageV2):
def get_supports_resumable_downloads(self):
return True
def get_direct_download_url(self, path, expires_in=60, requires_cors=False, head=False):
def get_direct_download_url(self, path, request_ip=None, expires_in=60, requires_cors=False, head=False):
self._initialize_cloud_conn()
path = self._init_path(path)
k = self._key_class(self._cloud_bucket, path)
@ -568,11 +568,11 @@ class RadosGWStorage(_CloudStorage):
storage_path, bucket_name, access_key, secret_key)
# TODO remove when radosgw supports cors: http://tracker.ceph.com/issues/8718#change-38624
def get_direct_download_url(self, path, expires_in=60, requires_cors=False, head=False):
def get_direct_download_url(self, path, request_ip=None, expires_in=60, requires_cors=False, head=False):
if requires_cors:
return None
return super(RadosGWStorage, self).get_direct_download_url(path, expires_in, requires_cors,
return super(RadosGWStorage, self).get_direct_download_url(path, request_ip, expires_in, requires_cors,
head)
# TODO remove when radosgw supports cors: http://tracker.ceph.com/issues/8718#change-38624

View file

@ -56,9 +56,9 @@ class DistributedStorage(StoragePaths):
cancel_chunked_upload = _location_aware(BaseStorageV2.cancel_chunked_upload)
def get_direct_download_url(self, locations, path, expires_in=600, requires_cors=False,
def get_direct_download_url(self, locations, path, request_ip=None, expires_in=600, requires_cors=False,
head=False):
download_url = self._get_direct_download_url(locations, path, expires_in, requires_cors, head)
download_url = self._get_direct_download_url(locations, path, request_ip, expires_in, requires_cors, head)
if download_url is None:
return None

View file

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

View file

@ -147,7 +147,7 @@ class SwiftStorage(BaseStorage):
logger.exception('Could not head object at path %s: %s', path, ex)
return None
def get_direct_download_url(self, object_path, expires_in=60, requires_cors=False, head=False):
def get_direct_download_url(self, object_path, request_ip=None, expires_in=60, requires_cors=False, head=False):
if requires_cors:
return None