Skip to content

Commit

Permalink
Enable redirects for ECR blob download requests (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
romasku authored Apr 26, 2022
1 parent 9e3b7c7 commit 64e9dfc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions platform_registry_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def __init__(
self._upstream_endpoint_url = upstream_endpoint_url
self._upstream_project = upstream_project

@property
def upstream_host(self) -> Optional[str]:
return self._upstream_endpoint_url.host

@property
def upstream_project(self) -> str:
return self._upstream_project
Expand Down Expand Up @@ -689,13 +693,19 @@ async def _proxy_request(
)
return response
else:
aws_blob_request = (
request.method == "GET"
and self._config.upstream_registry.type == UpstreamType.AWS_ECR
and path_components[-1] == "blobs"
)
async with self._registry_client.request(
method=request.method,
url=url,
headers=request_headers,
skip_auto_headers=("Content-Type",),
data=data,
timeout=timeout,
allow_redirects=aws_blob_request,
) as client_response:

logger.debug("upstream response: %s", client_response)
Expand Down Expand Up @@ -810,6 +820,9 @@ def _prepare_response_headers(
return response_headers

def _convert_location_header(self, url_str: str, url_factory: URLFactory) -> str:
url_raw = URL(url_str)
if url_raw.host != url_factory.upstream_host:
return url_str # Redirect to outer service, maybe AWS S3 redirect
upstream_repo_url = RepoURL.from_url(URL(url_str))
registry_repo_url = url_factory.create_registry_repo_url(upstream_repo_url)
logger.info(
Expand Down

0 comments on commit 64e9dfc

Please sign in to comment.