Fix an NPE when trying to pull a manifest without a legacy image via V1
This commit is contained in:
parent
d9da838df1
commit
b1dd053b02
6 changed files with 68 additions and 4 deletions
|
@ -12,6 +12,12 @@ class RegistryDataInterface(object):
|
|||
""" Returns whether the implementation of the data interface supports schema 2 format
|
||||
manifests. """
|
||||
|
||||
@abstractmethod
|
||||
def get_tag_legacy_image_id(self, repository_ref, tag_name, storage):
|
||||
""" Returns the legacy image ID for the tag with a legacy images in
|
||||
the repository. Returns None if None.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_legacy_tags_map(self, repository_ref, storage):
|
||||
""" Returns a map from tag name to its legacy image ID, for all tags with legacy images in
|
||||
|
|
|
@ -30,6 +30,25 @@ class OCIModel(SharedModel, RegistryDataInterface):
|
|||
manifests. """
|
||||
return True
|
||||
|
||||
def get_tag_legacy_image_id(self, repository_ref, tag_name, storage):
|
||||
""" Returns the legacy image ID for the tag with a legacy images in
|
||||
the repository. Returns None if None.
|
||||
"""
|
||||
tag = self.get_repo_tag(repository_ref, tag_name, include_legacy_image=True)
|
||||
if tag is None:
|
||||
return None
|
||||
|
||||
if tag.legacy_image_if_present is not None:
|
||||
return tag.legacy_image_if_present.docker_image_id
|
||||
|
||||
if tag.manifest.media_type == DOCKER_SCHEMA2_MANIFESTLIST_CONTENT_TYPE:
|
||||
# See if we can lookup a schema1 legacy image.
|
||||
v1_compatible = self.get_schema1_parsed_manifest(tag.manifest, '', '', '', storage)
|
||||
if v1_compatible is not None:
|
||||
return v1_compatible.leaf_layer_v1_image_id
|
||||
|
||||
return None
|
||||
|
||||
def get_legacy_tags_map(self, repository_ref, storage):
|
||||
""" Returns a map from tag name to its legacy image ID, for all tags with legacy images in
|
||||
the repository. Note that this can be a *very* heavy operation.
|
||||
|
@ -52,7 +71,6 @@ class OCIModel(SharedModel, RegistryDataInterface):
|
|||
if v1_id is not None:
|
||||
tags_map[tag.name] = v1_id
|
||||
|
||||
|
||||
return tags_map
|
||||
|
||||
def _get_legacy_compatible_image_for_manifest(self, manifest, storage):
|
||||
|
|
|
@ -33,6 +33,16 @@ class PreOCIModel(SharedModel, RegistryDataInterface):
|
|||
manifests. """
|
||||
return False
|
||||
|
||||
def get_tag_legacy_image_id(self, repository_ref, tag_name, storage):
|
||||
""" Returns the legacy image ID for the tag with a legacy images in
|
||||
the repository. Returns None if None.
|
||||
"""
|
||||
tag = self.get_repo_tag(repository_ref, tag_name, include_legacy_image=True)
|
||||
if tag is None:
|
||||
return None
|
||||
|
||||
return tag.legacy_image.docker_image_id
|
||||
|
||||
def get_legacy_tags_map(self, repository_ref, storage):
|
||||
""" Returns a map from tag name to its legacy image, for all tags with legacy images in
|
||||
the repository.
|
||||
|
|
Reference in a new issue