Skip to content

Commit

Permalink
Properly support OCI image manifest (#15268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 authored Dec 26, 2024
1 parent 617f2b4 commit 8321ed2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/middlewared/middlewared/plugins/apps_images/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .utils import (
DEFAULT_DOCKER_REGISTRY, DOCKER_AUTH_SERVICE, DOCKER_AUTH_HEADER, DOCKER_AUTH_URL, DOCKER_CONTENT_DIGEST_HEADER,
DOCKER_MANIFEST_LIST_SCHEMA_V2, DOCKER_MANIFEST_SCHEMA_V1, DOCKER_MANIFEST_SCHEMA_V2, DOCKER_RATELIMIT_URL,
parse_auth_header, parse_digest_from_schema,
DOCKER_MANIFEST_OCI_V1, parse_auth_header, parse_digest_from_schema,
)


Expand All @@ -29,7 +29,10 @@ async def _api_call(url, options=None, headers=None, mode='get'):
except asyncio.TimeoutError:
response['error'] = f'Unable to connect with {url} in {timeout} seconds.'
except aiohttp.ClientResponseError as e:
response['error'] = str(e)
response.update({
'error': str(e),
'error_obj': e,
})
else:
response['response_obj'] = req
if req.status != 200:
Expand Down Expand Up @@ -62,7 +65,7 @@ async def _get_manifest_response(self, registry, image, tag, headers, mode, rais
manifest_url = f'https://{registry}/v2/{image}/manifests/{tag}'
# 1) try getting manifest
response = await self._api_call(manifest_url, headers=headers, mode=mode)
if (error := response['error']) and isinstance(error, aiohttp.ClientResponseError):
if (error := response.get('error_obj')) and isinstance(error, aiohttp.ClientResponseError):
if error.status == 401:
# 2) try to get token from manifest api call's response headers
auth_data = parse_auth_header(error.headers[DOCKER_AUTH_HEADER])
Expand All @@ -88,7 +91,8 @@ async def _get_repo_digest(self, registry, image, tag):
registry, image, tag, await self.get_manifest_call_headers(registry, image, {
'Accept': (f'{DOCKER_MANIFEST_SCHEMA_V2}, '
f'{DOCKER_MANIFEST_LIST_SCHEMA_V2}, '
f'{DOCKER_MANIFEST_SCHEMA_V1}')
f'{DOCKER_MANIFEST_SCHEMA_V1}, '
f'{DOCKER_MANIFEST_OCI_V1}')
}), 'get', True
)
digests = parse_digest_from_schema(response)
Expand Down
1 change: 1 addition & 0 deletions src/middlewared/middlewared/plugins/apps_images/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DOCKER_AUTH_HEADER = 'WWW-Authenticate'
DOCKER_AUTH_URL = 'https://auth.docker.io/token'
DOCKER_AUTH_SERVICE = 'registry.docker.io'
DOCKER_MANIFEST_OCI_V1 = 'application/vnd.oci.image.index.v1+json'
DOCKER_MANIFEST_SCHEMA_V1 = 'application/vnd.docker.distribution.manifest.v1+json'
DOCKER_MANIFEST_SCHEMA_V2 = 'application/vnd.docker.distribution.manifest.v2+json'
DOCKER_MANIFEST_LIST_SCHEMA_V2 = 'application/vnd.docker.distribution.manifest.list.v2+json'
Expand Down

0 comments on commit 8321ed2

Please sign in to comment.