Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133046 / 24.10.2 / Properly support OCI image manifest (by Qubad786) #15271

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -9,7 +9,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 @@ -30,7 +30,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 @@ -63,7 +66,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 @@ -89,7 +92,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
Loading