From a9b858642346cd02259157ebdf4eb0023c6df706 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 11 Dec 2018 13:10:24 -0500 Subject: [PATCH] Make sure list_manifest_layers is not callable for manifest lists --- data/registry_model/interface.py | 4 ++-- data/registry_model/shared.py | 2 ++ endpoints/api/manifest.py | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/registry_model/interface.py b/data/registry_model/interface.py index e4cfacef1..060194c1c 100644 --- a/data/registry_model/interface.py +++ b/data/registry_model/interface.py @@ -199,7 +199,7 @@ class RegistryDataInterface(object): """ Returns an *ordered list* of the layers found in the manifest, starting at the base and working towards the leaf, including the associated Blob and its placements (if specified). The layer information in `layer_info` will be of type - `image.docker.types.ManifestImageLayer`. + `image.docker.types.ManifestImageLayer`. Should not be called for a manifest list. """ @abstractmethod @@ -208,7 +208,7 @@ class RegistryDataInterface(object): """ Returns an *ordered list* of the layers found in the parsed manifest, starting at the base and working towards the leaf, including the associated Blob and its placements (if specified). The layer information in `layer_info` will be of type - `image.docker.types.ManifestImageLayer`. + `image.docker.types.ManifestImageLayer`. Should not be called for a manifest list. """ @abstractmethod diff --git a/data/registry_model/shared.py b/data/registry_model/shared.py index ebed550af..16c87b96c 100644 --- a/data/registry_model/shared.py +++ b/data/registry_model/shared.py @@ -345,6 +345,8 @@ class SharedModel: working towards the leaf, including the associated Blob and its placements (if specified). Returns None if the manifest could not be parsed and validated. """ + assert not parsed.is_manifest_list + retriever = RepositoryContentRetriever(repo_id, storage) requires_empty_blob = parsed.get_requires_empty_layer_blob(retriever) diff --git a/endpoints/api/manifest.py b/endpoints/api/manifest.py index 32012d4cf..fa2d54e0d 100644 --- a/endpoints/api/manifest.py +++ b/endpoints/api/manifest.py @@ -58,10 +58,12 @@ def _manifest_dict(manifest): if manifest.legacy_image_if_present is not None: image = image_dict(manifest.legacy_image, with_history=True) - layers = registry_model.list_manifest_layers(manifest, storage) - if layers is None and not manifest.is_manifest_list: - logger.debug('Missing layers for manifest `%s`', manifest.digest) - abort(404) + layers = None + if not manifest.is_manifest_list: + layers = registry_model.list_manifest_layers(manifest, storage) + if layers is None: + logger.debug('Missing layers for manifest `%s`', manifest.digest) + abort(404) return { 'digest': manifest.digest,