Change registry data model to use a content retriever where applicable

This commit is contained in:
Joseph Schorr 2018-11-19 12:33:57 +02:00
parent 82ee21bfbd
commit 8a3427e55a
2 changed files with 11 additions and 12 deletions

View file

@ -6,10 +6,10 @@ from contextlib import contextmanager
from data import database from data import database
from data import model from data import model
from data.model import oci, DataModelException from data.model import oci, DataModelException
from data.model.oci.retriever import RepositoryContentRetriever
from data.database import db_transaction, Image from data.database import db_transaction, Image
from data.registry_model.interface import RegistryDataInterface from data.registry_model.interface import RegistryDataInterface
from data.registry_model.datatypes import (Tag, Manifest, LegacyImage, Label, SecurityScanStatus, from data.registry_model.datatypes import Tag, Manifest, LegacyImage, Label, SecurityScanStatus
RepositoryReference)
from data.registry_model.shared import SharedModel from data.registry_model.shared import SharedModel
from data.registry_model.label_handlers import apply_label_to_manifest from data.registry_model.label_handlers import apply_label_to_manifest
from image.docker import ManifestException from image.docker import ManifestException
@ -457,15 +457,7 @@ class OCIModel(SharedModel, RegistryDataInterface):
except database.Manifest.DoesNotExist: except database.Manifest.DoesNotExist:
return None return None
repository_ref = RepositoryReference.for_id(manifest_row.repository_id) retriever = RepositoryContentRetriever(manifest_row.repository_id, storage)
return parsed.get_v1_compatible_manifest(namespace_name, repo_name, tag_name, retriever)
def _lookup_blob(digest):
blob = self.get_repo_blob_by_digest(repository_ref, digest, include_placements=True)
if blob is None:
return None
return storage.get_content(blob.placements, blob.storage_path)
return parsed.get_v1_compatible_manifest(namespace_name, repo_name, tag_name, _lookup_blob)
oci_model = OCIModel() oci_model = OCIModel()

View file

@ -763,6 +763,13 @@ def test_create_manifest_and_retarget_tag(registry_model):
assert len(layers) == 1 assert len(layers) == 1
def test_get_schema1_parsed_manifest(registry_model):
repository_ref = registry_model.lookup_repository('devtable', 'simple')
latest_tag = registry_model.get_repo_tag(repository_ref, 'latest', include_legacy_image=True)
manifest = registry_model.get_manifest_for_tag(latest_tag)
assert registry_model.get_schema1_parsed_manifest(manifest, '', '', '', storage)
def test_create_manifest_and_retarget_tag_with_labels(registry_model): def test_create_manifest_and_retarget_tag_with_labels(registry_model):
repository_ref = registry_model.lookup_repository('devtable', 'simple') repository_ref = registry_model.lookup_repository('devtable', 'simple')
latest_tag = registry_model.get_repo_tag(repository_ref, 'latest', include_legacy_image=True) latest_tag = registry_model.get_repo_tag(repository_ref, 'latest', include_legacy_image=True)