Adjust usage of image model in manifest model

This commit is contained in:
Joseph Schorr 2018-08-20 16:47:38 -04:00
parent 584a18c0e1
commit 23ff49f0c1
3 changed files with 15 additions and 8 deletions

View file

@ -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/<apirepopath:repository>/image/<image_id>')
@ -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)

View file

@ -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),
}

View file

@ -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)