Switch content retrieval in manifests to be behind an interface

This allows for easy separation of retrieval of config blobs vs manifests
This commit is contained in:
Joseph Schorr 2018-11-19 11:55:52 +02:00
parent 1eaf5b18dd
commit cbfb6054e5
7 changed files with 143 additions and 124 deletions

View file

@ -71,14 +71,13 @@ class ManifestInterface(object):
"""
@abstractmethod
def child_manifests(self, lookup_manifest_fn):
def child_manifests(self, content_retriever):
""" Returns an iterator of all manifests that live under this manifest, if any or None if not
applicable. The lookup_manifest_fn is a function that, when given a blob content SHA,
returns the contents of that blob in storage if any or None if none.
applicable.
"""
@abstractmethod
def get_manifest_labels(self, lookup_config_fn):
def get_manifest_labels(self, content_retriever):
""" Returns a dictionary of all the labels defined inside this manifest or None if this kind
of manifest does not support labels. """
pass
@ -88,7 +87,7 @@ class ManifestInterface(object):
""" Returns an unsigned version of this manifest. """
@abstractmethod
def generate_legacy_layers(self, images_map, lookup_config_fn):
def generate_legacy_layers(self, images_map, content_retriever):
"""
Rewrites Docker v1 image IDs and returns a generator of DockerV1Metadata.
@ -100,7 +99,19 @@ class ManifestInterface(object):
"""
@abstractmethod
def get_v1_compatible_manifest(self, namespace_name, repo_name, tag_name, lookup_fn):
def get_v1_compatible_manifest(self, namespace_name, repo_name, tag_name, content_retriever):
""" Returns the manifest that is compatible with V1, by virtue of being `amd64` and `linux`.
If none, returns None.
"""
@add_metaclass(ABCMeta)
class ContentRetriever(object):
""" Defines the interface for retrieval of various content referneced by a manifest. """
@abstractmethod
def get_manifest_bytes_with_digest(self, digest):
""" Returns the bytes of the manifest with the given digest or None if none found. """
@abstractmethod
def get_blob_bytes_with_digest(self, digest):
""" Returns the bytes of the blob with the given digest or None if none found. """