Fix verbs in manifestlist
All registry_tests now pass
This commit is contained in:
parent
783c9e7a73
commit
3c8b87e086
18 changed files with 517 additions and 247 deletions
|
@ -7,10 +7,15 @@ from data import model, database
|
|||
from data.model import DataModelException
|
||||
from image.docker.v1 import DockerV1Metadata
|
||||
|
||||
|
||||
_MEDIA_TYPE = "application/vnd.docker.distribution.manifest.v1+prettyjws"
|
||||
|
||||
|
||||
class Repository(namedtuple('Repository', ['id', 'name', 'namespace_name', 'description',
|
||||
'is_public'])):
|
||||
"""
|
||||
Repository represents a namespaced collection of tags.
|
||||
"""
|
||||
|
||||
class ManifestJSON(namedtuple('ManifestJSON', ['digest', 'json', 'media_type'])):
|
||||
"""
|
||||
ManifestJSON represents a Manifest of any format.
|
||||
|
@ -44,47 +49,6 @@ class RepositoryReference(namedtuple('RepositoryReference', ['id', 'name', 'name
|
|||
"""
|
||||
|
||||
|
||||
class Repository(namedtuple('Repository', ['id', 'name', 'namespace_name', 'description',
|
||||
'is_public'])):
|
||||
"""
|
||||
Repository represents a namespaced collection of tags.
|
||||
"""
|
||||
|
||||
|
||||
def _repository_for_repo(repo):
|
||||
"""
|
||||
Returns a Repository object representing the repo data model instance given.
|
||||
"""
|
||||
return Repository(
|
||||
id=repo.id,
|
||||
name=repo.name,
|
||||
namespace_name=repo.namespace_user.username,
|
||||
description=repo.description,
|
||||
is_public=model.repository.is_repository_public(repo)
|
||||
)
|
||||
|
||||
|
||||
def _docker_v1_metadata(namespace_name, repo_name, repo_image):
|
||||
"""
|
||||
Returns a DockerV1Metadata object for the given image under the repository with the given
|
||||
namespace and name. Note that the namespace and name are passed here as an optimization, and are
|
||||
*not checked* against the image.
|
||||
"""
|
||||
return DockerV1Metadata(
|
||||
namespace_name=namespace_name,
|
||||
repo_name=repo_name,
|
||||
image_id=repo_image.docker_image_id,
|
||||
checksum=repo_image.v1_checksum,
|
||||
content_checksum=repo_image.storage.content_checksum,
|
||||
compat_json=repo_image.v1_json_metadata,
|
||||
created=repo_image.created,
|
||||
comment=repo_image.comment,
|
||||
command=repo_image.command,
|
||||
# TODO: make sure this isn't needed anywhere, as it is expensive to lookup
|
||||
parent_image_id=None,
|
||||
)
|
||||
|
||||
|
||||
class DockerRegistryV2DataInterface(object):
|
||||
"""
|
||||
Interface that represents all data store interactions required by a Docker Registry v1.
|
||||
|
@ -303,12 +267,23 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
def repository_is_public(cls, namespace_name, repo_name):
|
||||
return model.repository.repository_is_public(namespace_name, repo_name)
|
||||
|
||||
@classmethod
|
||||
def _repository_for_repo(cls, repo):
|
||||
""" Returns a Repository object representing the repo data model instance given. """
|
||||
return Repository(
|
||||
id=repo.id,
|
||||
name=repo.name,
|
||||
namespace_name=repo.namespace_user.username,
|
||||
description=repo.description,
|
||||
is_public=model.repository.is_repository_public(repo)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_repository(cls, namespace_name, repo_name):
|
||||
repo = model.repository.get_repository(namespace_name, repo_name)
|
||||
if repo is None:
|
||||
return None
|
||||
return _repository_for_repo(repo)
|
||||
return cls._repository_for_repo(repo)
|
||||
|
||||
@classmethod
|
||||
def has_active_tag(cls, namespace_name, repo_name, tag_name):
|
||||
|
@ -349,11 +324,32 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
tags = model.tag.delete_manifest_by_digest(namespace_name, repo_name, digest)
|
||||
return [_tag_view(tag) for tag in tags]
|
||||
|
||||
@classmethod
|
||||
def _docker_v1_metadata(cls, namespace_name, repo_name, repo_image):
|
||||
"""
|
||||
Returns a DockerV1Metadata object for the given image under the repository with the given
|
||||
namespace and name. Note that the namespace and name are passed here as an optimization, and are
|
||||
*not checked* against the image.
|
||||
"""
|
||||
return DockerV1Metadata(
|
||||
namespace_name=namespace_name,
|
||||
repo_name=repo_name,
|
||||
image_id=repo_image.docker_image_id,
|
||||
checksum=repo_image.v1_checksum,
|
||||
content_checksum=repo_image.storage.content_checksum,
|
||||
compat_json=repo_image.v1_json_metadata,
|
||||
created=repo_image.created,
|
||||
comment=repo_image.comment,
|
||||
command=repo_image.command,
|
||||
# TODO: make sure this isn't needed anywhere, as it is expensive to lookup
|
||||
parent_image_id=None,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_docker_v1_metadata_by_tag(cls, namespace_name, repo_name, tag_name):
|
||||
try:
|
||||
repo_img = model.tag.get_tag_image(namespace_name, repo_name, tag_name, include_storage=True)
|
||||
return _docker_v1_metadata(namespace_name, repo_name, repo_img)
|
||||
return cls._docker_v1_metadata(namespace_name, repo_name, repo_img)
|
||||
except DataModelException:
|
||||
return None
|
||||
|
||||
|
@ -364,7 +360,7 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
return {}
|
||||
|
||||
images_query = model.image.lookup_repository_images(repo, docker_image_ids)
|
||||
return {image.docker_image_id: _docker_v1_metadata(namespace_name, repo_name, image)
|
||||
return {image.docker_image_id: cls._docker_v1_metadata(namespace_name, repo_name, image)
|
||||
for image in images_query}
|
||||
|
||||
@classmethod
|
||||
|
@ -374,7 +370,7 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
return []
|
||||
|
||||
parents = model.image.get_parent_images(namespace_name, repo_name, repo_image)
|
||||
return [_docker_v1_metadata(namespace_name, repo_name, image) for image in parents]
|
||||
return [cls._docker_v1_metadata(namespace_name, repo_name, image) for image in parents]
|
||||
|
||||
@classmethod
|
||||
def create_manifest_and_update_tag(cls, namespace_name, repo_name, tag_name, manifest_digest,
|
||||
|
@ -406,7 +402,7 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
|
||||
repo_image = model.image.synthesize_v1_image(repo, storage_obj, image_id, created, comment,
|
||||
command, compat_json, parent_image)
|
||||
return _docker_v1_metadata(repo.namespace_user.username, repo.name, repo_image)
|
||||
return cls._docker_v1_metadata(repo.namespace_user.username, repo.name, repo_image)
|
||||
|
||||
@classmethod
|
||||
def save_manifest(cls, namespace_name, repo_name, tag_name, leaf_layer_docker_id, manifest_digest,
|
||||
|
@ -434,7 +430,7 @@ class PreOCIModel(DockerRegistryV2DataInterface):
|
|||
def get_visible_repositories(cls, username, limit, offset):
|
||||
query = model.repository.get_visible_repositories(username, include_public=(username is None))
|
||||
query = query.limit(limit).offset(offset)
|
||||
return [_repository_for_repo(repo) for repo in query]
|
||||
return [cls._repository_for_repo(repo) for repo in query]
|
||||
|
||||
@classmethod
|
||||
def create_blob_upload(cls, namespace_name, repo_name, upload_uuid, location_name,
|
||||
|
|
Reference in a new issue