1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/image/shared/schemas.py
Kenny Lee Sin Cheong 4546163e83 registry: implements the OCI 1.1 referrers API (PROJQUAY-7280) (#2597)
* registry: implements the OCI 1.1 referrers API

Migrations:
- Adds a subject column for lookup
- Adds a subject_backfilled column to track status of the backfilling
of existing manifests
- Adds a manifest_json column making use of postgres' JSONB support,
for future use.

Manifestsubjectbackfillworker: Indexes existing manifests for possible
existing subject field.

* Deprecate IGNORE_UNKNOWN_MEDIATYPES

* Cleanup
2024-06-07 13:28:13 -04:00

55 lines
2.0 KiB
Python

from image.docker.schema1 import DOCKER_SCHEMA1_CONTENT_TYPES, DockerSchema1Manifest
from image.docker.schema2 import (
DOCKER_SCHEMA2_MANIFEST_CONTENT_TYPE,
DOCKER_SCHEMA2_MANIFESTLIST_CONTENT_TYPE,
)
from image.docker.schema2.list import DockerSchema2ManifestList
from image.docker.schema2.manifest import DockerSchema2Manifest
from image.oci import OCI_IMAGE_INDEX_CONTENT_TYPE, OCI_IMAGE_MANIFEST_CONTENT_TYPE
from image.oci.index import OCIIndex
from image.oci.manifest import OCIManifest
from image.shared import ManifestException
from image.shared.types import SparseManifestList
from util.bytes import Bytes
MANIFEST_LIST_TYPES = [DOCKER_SCHEMA2_MANIFESTLIST_CONTENT_TYPE, OCI_IMAGE_INDEX_CONTENT_TYPE]
def is_manifest_list_type(content_type):
"""Returns True if the given content type refers to a manifest list of some kind."""
return content_type in MANIFEST_LIST_TYPES
def parse_manifest_from_bytes(
manifest_bytes,
media_type,
validate=True,
sparse_manifest_support=False,
):
"""
Parses and returns a manifest from the given bytes, for the given media type.
Raises a ManifestException if the parse fails for some reason.
"""
assert isinstance(manifest_bytes, Bytes)
if is_manifest_list_type(media_type) and sparse_manifest_support:
return SparseManifestList(manifest_bytes, media_type)
if media_type == DOCKER_SCHEMA2_MANIFEST_CONTENT_TYPE:
return DockerSchema2Manifest(manifest_bytes)
if media_type == DOCKER_SCHEMA2_MANIFESTLIST_CONTENT_TYPE:
return DockerSchema2ManifestList(manifest_bytes)
if media_type == OCI_IMAGE_MANIFEST_CONTENT_TYPE:
return OCIManifest(manifest_bytes)
if media_type == OCI_IMAGE_INDEX_CONTENT_TYPE:
return OCIIndex(manifest_bytes)
if media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
return DockerSchema1Manifest(manifest_bytes, validate=validate)
raise ManifestException("Unknown or unsupported manifest media type `%s`" % media_type)