refactor(data+endpoints): code review changes
this puts the view logic on the object and adds a parameter for logging [TESTING->locally with docker compose] Issue: https://coreosdev.atlassian.net/browse/QUAY-632 - [ ] It works! - [ ] Comments provide sufficient explanations for the next contributor - [ ] Tests cover changes and corner cases - [ ] Follows Quay syntax patterns and format
This commit is contained in:
parent
897a091692
commit
131acde317
6 changed files with 73 additions and 70 deletions
|
@ -7,7 +7,6 @@ from data.model import DataModelException
|
|||
from endpoints.api import (resource, nickname, require_repo_read, require_repo_write,
|
||||
RepositoryParamResource, log_action, validate_json_request, path_param,
|
||||
parse_args, query_param, truthy_bool, disallow_for_app_repositories)
|
||||
from endpoints.api.image import image_view_pre_oci
|
||||
from endpoints.api.tag_models_interface import Repository
|
||||
from endpoints.api.tag_models_pre_oci import pre_oci_model as model
|
||||
from endpoints.exception import NotFound
|
||||
|
@ -15,25 +14,6 @@ from endpoints.v2.manifest import _generate_and_store_manifest
|
|||
from util.names import TAG_ERROR, TAG_REGEX
|
||||
|
||||
|
||||
def tag_view(tag):
|
||||
tag_info = {
|
||||
'name': tag.name,
|
||||
'docker_image_id': tag.docker_image_id,
|
||||
'reversion': tag.reversion,
|
||||
}
|
||||
|
||||
if tag.lifetime_start_ts > 0:
|
||||
tag_info['start_ts'] = tag.lifetime_start_ts
|
||||
|
||||
if tag.lifetime_end_ts > 0:
|
||||
tag_info['end_ts'] = tag.lifetime_end_ts
|
||||
|
||||
if tag.manifest_list:
|
||||
tag_info['manifest_digest'] = tag.manifest_list
|
||||
|
||||
return tag_info
|
||||
|
||||
|
||||
@resource('/v1/repository/<apirepopath:repository>/tag/')
|
||||
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
|
||||
class ListRepositoryTags(RepositoryParamResource):
|
||||
|
@ -60,7 +40,7 @@ class ListRepositoryTags(RepositoryParamResource):
|
|||
raise NotFound()
|
||||
|
||||
return {
|
||||
'tags': [tag_view(tag) for tag in tag_history.tags],
|
||||
'tags': [tag.to_dict() for tag in tag_history.tags],
|
||||
'page': page,
|
||||
'has_additional': tag_history.more,
|
||||
}
|
||||
|
@ -111,7 +91,7 @@ class RepositoryTag(RepositoryParamResource):
|
|||
'namespace': namespace,
|
||||
'image': image_id,
|
||||
'original_image': original_image_id
|
||||
}, repo=repo)
|
||||
}, repo_name=repository)
|
||||
|
||||
_generate_and_store_manifest(namespace, repository, tag)
|
||||
|
||||
|
@ -129,7 +109,7 @@ class RepositoryTag(RepositoryParamResource):
|
|||
{'username': username,
|
||||
'repo': repository,
|
||||
'namespace': namespace,
|
||||
'tag': tag}, repo=Repository(namespace_name=namespace, repository_name=repository))
|
||||
'tag': tag}, repo_name=repository)
|
||||
|
||||
return '', 204
|
||||
|
||||
|
@ -154,6 +134,9 @@ class RepositoryTagImages(RepositoryParamResource):
|
|||
except DataModelException:
|
||||
raise NotFound()
|
||||
|
||||
if tag_image is None:
|
||||
raise NotFound()
|
||||
|
||||
parent_images = model.get_parent_images(namespace, repository, tag_image.docker_image_id)
|
||||
image_map = {str(tag_image.docker_image_id): tag_image}
|
||||
|
||||
|
@ -181,7 +164,7 @@ class RepositoryTagImages(RepositoryParamResource):
|
|||
|
||||
return {
|
||||
'images': [
|
||||
image_view_pre_oci(image, image_map_all) for image in all_images
|
||||
image.to_dict(image_map_all) for image in all_images
|
||||
if not parsed_args['owned'] or (str(image.docker_image_id) in image_map)
|
||||
]
|
||||
}
|
||||
|
@ -239,7 +222,7 @@ class RestoreTag(RepositoryParamResource):
|
|||
if existing_image is not None:
|
||||
log_data['original_image'] = existing_image.docker_image_id
|
||||
|
||||
log_action('revert_tag', namespace, log_data, repo=repo)
|
||||
log_action('revert_tag', namespace, log_data, repo_name=repository)
|
||||
|
||||
return {
|
||||
'image_id': image_id,
|
||||
|
|
Reference in a new issue