Add interface function for deleting tags pointing to a manifest

This commit is contained in:
Joseph Schorr 2018-09-20 15:49:20 -04:00
parent bb01e08d44
commit 8cfb3f4fe8
3 changed files with 35 additions and 3 deletions

View file

@ -82,7 +82,8 @@ class RegistryDataInterface(object):
""" """
@abstractmethod @abstractmethod
def list_repository_tag_history(self, repository_ref, page=1, size=100, specific_tag_name=None, active_tags_only=False): def list_repository_tag_history(self, repository_ref, page=1, size=100, specific_tag_name=None,
active_tags_only=False):
""" """
Returns the history of all tags in the repository (unless filtered). This includes tags that Returns the history of all tags in the repository (unless filtered). This includes tags that
have been made in-active due to newer versions of those tags coming into service. have been made in-active due to newer versions of those tags coming into service.
@ -110,6 +111,13 @@ class RegistryDataInterface(object):
Deletes the latest, *active* tag with the given name in the repository. Deletes the latest, *active* tag with the given name in the repository.
""" """
@abstractmethod
def delete_tags_for_manifest(self, manifest):
"""
Deletes all tags pointing to the given manifest, making the manifest inaccessible for pulling.
Returns the tags deleted, if any. Returns None on error.
"""
@abstractmethod @abstractmethod
def change_repository_tag_expiration(self, tag, expiration_date): def change_repository_tag_expiration(self, tag, expiration_date):
""" Sets the expiration date of the tag under the matching repository to that given. If the """ Sets the expiration date of the tag under the matching repository to that given. If the

View file

@ -241,6 +241,21 @@ class PreOCIModel(RegistryDataInterface):
deleted_tag = model.tag.delete_tag(repo.namespace_user.username, repo.name, tag_name) deleted_tag = model.tag.delete_tag(repo.namespace_user.username, repo.name, tag_name)
return Tag.for_repository_tag(deleted_tag) return Tag.for_repository_tag(deleted_tag)
def delete_tags_for_manifest(self, manifest):
"""
Deletes all tags pointing to the given manifest, making the manifest inaccessible for pulling.
Returns the tags deleted, if any. Returns None on error.
"""
try:
tagmanifest = database.TagManifest.get(id=manifest._db_id)
except database.TagManifest.DoesNotExist:
return None
namespace_name = tagmanifest.tag.repository.namespace_user.username
repo_name = tagmanifest.tag.repository.name
tags = model.tag.delete_manifest_by_digest(namespace_name, repo_name, manifest.digest)
return [Tag.for_repository_tag(tag) for tag in tags]
def change_repository_tag_expiration(self, tag, expiration_date): def change_repository_tag_expiration(self, tag, expiration_date):
""" Sets the expiration date of the tag under the matching repository to that given. If the """ Sets the expiration date of the tag under the matching repository to that given. If the
expiration date is None, then the tag will not expire. Returns a tuple of the previous expiration date is None, then the tag will not expire. Returns a tuple of the previous

View file

@ -209,7 +209,11 @@ def test_repository_tag_history(pre_oci_model):
('devtable', 'history'), ('devtable', 'history'),
('buynlarge', 'orgrepo'), ('buynlarge', 'orgrepo'),
]) ])
def test_delete_tags(repo_namespace, repo_name, pre_oci_model): @pytest.mark.parametrize('via_manifest', [
False,
True,
])
def test_delete_tags(repo_namespace, repo_name, via_manifest, pre_oci_model):
repository_ref = pre_oci_model.lookup_repository(repo_namespace, repo_name) repository_ref = pre_oci_model.lookup_repository(repo_namespace, repo_name)
tags = pre_oci_model.list_repository_tags(repository_ref) tags = pre_oci_model.list_repository_tags(repository_ref)
assert len(tags) assert len(tags)
@ -220,7 +224,12 @@ def test_delete_tags(repo_namespace, repo_name, pre_oci_model):
# Delete every tag in the repository. # Delete every tag in the repository.
for tag in tags: for tag in tags:
if via_manifest:
assert pre_oci_model.delete_tag(repository_ref, tag.name) assert pre_oci_model.delete_tag(repository_ref, tag.name)
else:
manifest = pre_oci_model.get_manifest_for_tag(tag)
if manifest is not None:
assert pre_oci_model.delete_tags_for_manifest(manifest)
# Make sure the tag is no longer found. # Make sure the tag is no longer found.
with assert_query_count(1): with assert_query_count(1):