From 23ff49f0c1c9753a6a888a11f381a74edcff0cbf Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 20 Aug 2018 16:47:38 -0400 Subject: [PATCH] Adjust usage of image model in manifest model --- endpoints/api/image.py | 8 ++++---- endpoints/api/manifest_models_interface.py | 3 ++- endpoints/api/manifest_models_pre_oci.py | 12 +++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/endpoints/api/image.py b/endpoints/api/image.py index f126ed89e..53c4bf68b 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -7,7 +7,7 @@ from endpoints.api import (resource, nickname, require_repo_read, RepositoryPara from endpoints.exception import NotFound -def _image_dict(image, with_history=False, with_tags=False): +def image_dict(image, with_history=False, with_tags=False): image_data = { 'id': image.docker_image_id, 'created': format_date(image.created), @@ -22,7 +22,7 @@ def _image_dict(image, with_history=False, with_tags=False): image_data['tags'] = [tag.name for tag in image.tags] if with_history: - image_data['history'] = [_image_dict(parent, with_history, with_tags) + image_data['history'] = [image_dict(parent, with_history, with_tags) for parent in image.parents] # Calculate the ancestors string, with the DBID's replaced with the docker IDs. @@ -46,7 +46,7 @@ class RepositoryImageList(RepositoryParamResource): raise NotFound() images = registry_model.get_legacy_images(repo_ref) - return {'images': [_image_dict(image, with_tags=True) for image in images]} + return {'images': [image_dict(image, with_tags=True) for image in images]} @resource('/v1/repository//image/') @@ -68,4 +68,4 @@ class RepositoryImage(RepositoryParamResource): if image is None: raise NotFound() - return _image_dict(image, with_history=True) + return image_dict(image, with_history=True) diff --git a/endpoints/api/manifest_models_interface.py b/endpoints/api/manifest_models_interface.py index 03615b208..539399b2b 100644 --- a/endpoints/api/manifest_models_interface.py +++ b/endpoints/api/manifest_models_interface.py @@ -1,6 +1,7 @@ from abc import ABCMeta, abstractmethod from collections import namedtuple +from endpoints.api.image import image_dict from six import add_metaclass @@ -40,7 +41,7 @@ class ManifestAndImage( return { 'digest': self.digest, 'manifest_data': self.manifest_data, - 'image': self.image.to_dict(), + 'image': image_dict(self.image), } diff --git a/endpoints/api/manifest_models_pre_oci.py b/endpoints/api/manifest_models_pre_oci.py index a5d3d78af..6a40eb76a 100644 --- a/endpoints/api/manifest_models_pre_oci.py +++ b/endpoints/api/manifest_models_pre_oci.py @@ -2,7 +2,7 @@ import json from manifest_models_interface import ManifestLabel, ManifestLabelInterface, ManifestAndImage from data import model -from image_models_pre_oci import pre_oci_model as image_models +from data.registry_model import registry_model class ManifestLabelPreOCI(ManifestLabelInterface): @@ -47,8 +47,14 @@ class ManifestLabelPreOCI(ManifestLabelInterface): return None # TODO: remove this dependency on image once we've moved to the new data model. - image = image_models.get_repository_image(namespace_name, repository_name, - tag_manifest.tag.image.docker_image_id) + repo_ref = registry_model.lookup_repository(namespace_name, repository_name) + if repo_ref is None: + return None + + image = registry_model.get_legacy_image(repo_ref, tag_manifest.tag.image.docker_image_id, + include_parents=True) + if image is None: + return None manifest_data = json.loads(tag_manifest.json_data) return ManifestAndImage(digest=digest, manifest_data=manifest_data, image=image)