Skip to content

Commit

Permalink
Add tag/untag commands for container repositories
Browse files Browse the repository at this point in the history
fixes: pulp#423
  • Loading branch information
gerrod3 committed Nov 12, 2021
1 parent 59d2eb5 commit 5b51ae1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/423.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added tag/untag commands to add and remove tags from images in container repositories.
5 changes: 5 additions & 0 deletions pulpcore/cli/container/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gettext
from typing import ClassVar

from pulpcore.cli.common.context import (
EntityDefinition,
Expand Down Expand Up @@ -75,6 +76,8 @@ class PulpContainerRepositoryContext(PulpRepositoryContext):
UPDATE_ID = "repositories_container_container_partial_update"
DELETE_ID = "repositories_container_container_delete"
SYNC_ID = "repositories_container_container_sync"
TAG_ID: ClassVar[str] = "repositories_container_container_tag"
UNTAG_ID: ClassVar[str] = "repositories_container_container_untag"
VERSION_CONTEXT = PulpContainerRepositoryVersionContext
CAPABILITIES = {
"sync": [PluginRequirement("container")],
Expand All @@ -89,6 +92,8 @@ class PulpContainerPushRepositoryContext(PulpRepositoryContext):
# CREATE_ID = "repositories_container_container_push_create"
# UPDATE_ID = "repositories_container_container_push_update"
# DELETE_ID = "repositories_container_container_push_delete"
TAG_ID: ClassVar[str] = "repositories_container_push_tag"
UNTAG_ID: ClassVar[str] = "repositories_container_push_untag"
VERSION_CONTEXT = PulpContainerPushRepositoryVersionContext


Expand Down
39 changes: 39 additions & 0 deletions pulpcore/cli/container/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,42 @@ def sync(
href=repository_href,
body=body,
)


@repository.command(name="tag")
@name_option
@href_option
@click.option("--tag", help=_("Name to tag an image with"), required=True)
@click.option("--digest", help=_("SHA256 digest of the Manifest file"), required=True)
@pass_repository_context
def add_tag(repository_ctx: PulpRepositoryContext, digest: str, tag: str,) -> None:
if len(tag) == 0:
raise click.ClickException("Please pass a non empty tag name.")

digest = digest.strip()
if not digest.startswith("sha256:"):
digest = f"sha256:{digest}"
if len(digest) != 71: # len("sha256:" + 64
raise click.ClickException("Improper SHA256, please provide a valid 64 digit digest.")

repository_ctx.pulp_ctx.call(
repository_ctx.TAG_ID,
parameters={repository_ctx.HREF: repository_ctx.pulp_href},
body={"tag": tag, "digest": digest},
)


@repository.command(name="untag")
@name_option
@href_option
@click.option("--tag", help=_("Name of tag to remove"), required=True)
@pass_repository_context
def remove_tag(repository_ctx: PulpRepositoryContext, tag: str) -> None:
if len(tag) == 0:
raise click.ClickException("Please pass a non empty tag name.")

repository_ctx.pulp_ctx.call(
repository_ctx.UNTAG_ID,
parameters={repository_ctx.HREF: repository_ctx.pulp_href},
body={"tag": tag},
)

0 comments on commit 5b51ae1

Please sign in to comment.