Fix some bugs in the tags registry api.

This commit is contained in:
yackob03 2013-11-07 17:09:15 -05:00
parent 1e72644ef8
commit 603ad53f6a
2 changed files with 24 additions and 9 deletions

View file

@ -640,9 +640,18 @@ def get_parent_images(image_obj):
def create_or_update_tag(namespace_name, repository_name, tag_name, def create_or_update_tag(namespace_name, repository_name, tag_name,
tag_docker_image_id): tag_docker_image_id):
repo = Repository.get(Repository.name == repository_name, try:
Repository.namespace == namespace_name) repo = Repository.get(Repository.name == repository_name,
image = Image.get(Image.docker_image_id == tag_docker_image_id) Repository.namespace == namespace_name)
except Repository.DoesNotExist:
raise DataModelException('Invalid repository %s/%s' %
(namespace_name, repository_name))
try:
image = Image.get(Image.docker_image_id == tag_docker_image_id)
except Image.DoesNotExist:
raise DataModelException('Invalid image with id: %s' %
tag_docker_image_id)
try: try:
tag = RepositoryTag.get(RepositoryTag.repository == repo, tag = RepositoryTag.get(RepositoryTag.repository == repo,
@ -656,11 +665,17 @@ def create_or_update_tag(namespace_name, repository_name, tag_name,
def delete_tag(namespace_name, repository_name, tag_name): def delete_tag(namespace_name, repository_name, tag_name):
repo = Repository.get(Repository.name == repository_name, joined = RepositoryTag.select().join(Repository)
Repository.namespace == namespace_name) found = list(joined.where(Repository.name == repository_name,
tag = RepositoryTag.get(RepositoryTag.repository == repo, Repository.namespace == namespace_name,
RepositoryTag.name == tag_name) RepositoryTag.name == tag_name))
tag.delete_instance()
if not found:
msg = ('Invalid repository tag \'%s\' on repository \'%s/%s\'' %
(tag_name, namespace_name, repository_name))
raise DataModelException(msg)
found[0].delete_instance()
def delete_all_repository_tags(namespace_name, repository_name): def delete_all_repository_tags(namespace_name, repository_name):

View file

@ -68,7 +68,7 @@ def delete_tag(namespace, repository, tag):
permission = ModifyRepositoryPermission(namespace, repository) permission = ModifyRepositoryPermission(namespace, repository)
if permission.can(): if permission.can():
model.delete_tag(namespace, repository, tag_name) model.delete_tag(namespace, repository, tag)
return make_response('Deleted', 204) return make_response('Deleted', 204)