Skip to content

Commit

Permalink
storage: Redirect in network request to return s3 signed URL(PROJQUAY…
Browse files Browse the repository at this point in the history
…-8489)

Signed-off-by: harishsurf <hgovinda@redhat.com>
  • Loading branch information
harishsurf committed Jan 28, 2025
1 parent 395d7d6 commit a66abbd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion storage/akamaistorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

logger = logging.getLogger(__name__)

from storage.cloud import S3Storage
from storage.cloud import S3Storage, is_in_network_request

DEFAULT_SIGNED_URL_EXPIRY_SECONDS = 900 # 15 mins
TOKEN_QUERY_STRING = "akamai_signature"
Expand Down Expand Up @@ -49,6 +49,19 @@ def get_direct_download_url(
s3_presigned_url = super(AkamaiS3Storage, self).get_direct_download_url(
path, request_ip, expires_in, requires_cors, head
)
logger.debug(f"s3 presigned_url: {s3_presigned_url}")
if request_ip is None:
return s3_presigned_url

if is_in_network_request(self._context, request_ip, self.region):
if kwargs.get("cdn_specific", False):
logger.debug(
"Request came from within network but namespace is protected: %s", path
)
else:
logger.debug("Request is from within the network, returning S3 URL")
return s3_presigned_url

s3_url_parsed = urllib.parse.urlparse(s3_presigned_url)

# replace s3 location with Akamai domain
Expand Down

0 comments on commit a66abbd

Please sign in to comment.