Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1137.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for content label commands, requires pulpcore 3.73.2 or later.
11 changes: 10 additions & 1 deletion pulpcore/cli/ansible/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
PulpAnsibleRepositoryContext,
PulpAnsibleRoleContext,
)
from pulp_glue.common.context import PulpContentContext, PulpRepositoryContext
from pulp_glue.common.context import PluginRequirement, PulpContentContext, PulpRepositoryContext
from pulp_glue.common.i18n import get_translation
from pulp_glue.core.context import PulpArtifactContext

from pulp_cli.generic import (
GroupOption,
PulpCLIContext,
href_option,
label_command,
label_select_option,
list_command,
parse_size_callback,
pass_content_context,
Expand Down Expand Up @@ -114,6 +116,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
help=_("Signing service used to create {entity}"),
allowed_with_contexts=signature_context,
),
label_select_option,
]

lookup_options = [
Expand Down Expand Up @@ -165,6 +168,12 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)

content.add_command(list_command(decorators=list_options))
content.add_command(show_command(decorators=lookup_options))
content.add_command(
label_command(
decorators=lookup_options,
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
)
)


# This is a mypy bug getting confused with positional args
Expand Down
15 changes: 12 additions & 3 deletions pulpcore/cli/container/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as t

import click
from pulp_glue.common.context import PulpEntityContext
from pulp_glue.common.context import PluginRequirement, PulpEntityContext
from pulp_glue.container.context import (
PulpContainerBlobContext,
PulpContainerManifestContext,
Expand All @@ -13,6 +13,8 @@
GroupOption,
PulpCLIContext,
href_option,
label_command,
label_select_option,
list_command,
pass_pulp_context,
pulp_group,
Expand Down Expand Up @@ -60,9 +62,10 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
pulp_option(
"--name-in", "name__in", multiple=True, allowed_with_contexts=(PulpContainerTagContext,)
),
label_select_option,
]

show_options = [
lookup_options = [
pulp_option(
"--digest",
expose_value=False,
Expand Down Expand Up @@ -95,4 +98,10 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
]

content.add_command(list_command(decorators=list_options))
content.add_command(show_command(decorators=show_options))
content.add_command(show_command(decorators=lookup_options))
content.add_command(
label_command(
decorators=lookup_options,
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
)
)
6 changes: 3 additions & 3 deletions pulpcore/cli/container/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
update_command,
version_command,
)
from pulpcore.cli.container.content import show_options
from pulpcore.cli.container.content import lookup_options as content_lookup_options
from pulpcore.cli.core.generic import task_command

translation = get_translation(__package__)
Expand Down Expand Up @@ -133,8 +133,8 @@ def repository() -> None:
repository.add_command(
repository_content_command(
contexts=contexts,
add_decorators=show_options,
remove_decorators=show_options,
add_decorators=content_lookup_options,
remove_decorators=content_lookup_options,
allowed_with_contexts=container_context,
base_default_plugin="container",
base_default_type="container",
Expand Down
9 changes: 9 additions & 0 deletions pulpcore/cli/file/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
chunk_size_option,
create_command,
href_option,
label_command,
label_select_option,
list_command,
pass_entity_context,
pass_pulp_context,
Expand Down Expand Up @@ -109,11 +111,18 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
decorators=[
click.option("--relative-path"),
click.option("--sha256"),
label_select_option,
]
)
)
content.add_command(show_command(decorators=lookup_options))
content.add_command(create_command(decorators=create_options))
content.add_command(
label_command(
decorators=lookup_options,
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
)
)


@content.command()
Expand Down
12 changes: 11 additions & 1 deletion pulpcore/cli/python/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
chunk_size_option,
create_command,
href_option,
label_command,
label_select_option,
list_command,
pass_entity_context,
pass_pulp_context,
Expand Down Expand Up @@ -81,15 +83,23 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
needs_plugins=[PluginRequirement("core", specifier=">=3.56.1")],
),
]
lookup_options = [href_option]
content.add_command(
list_command(
decorators=[
click.option("--filename", type=str),
label_select_option,
]
)
)
content.add_command(show_command(decorators=[href_option]))
content.add_command(show_command(decorators=lookup_options))
content.add_command(create_command(decorators=create_options))
content.add_command(
label_command(
decorators=lookup_options,
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
)
)


@content.command()
Expand Down
9 changes: 9 additions & 0 deletions pulpcore/cli/rpm/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
exclude_field_option,
field_option,
href_option,
label_command,
label_select_option,
list_command,
pass_entity_context,
pass_pulp_context,
Expand Down Expand Up @@ -240,6 +242,7 @@ def content() -> None:
"--version-in", "version__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,)
),
pulp_option("--version-ne", "version__ne", allowed_with_contexts=(PulpRpmPackageContext,)),
label_select_option,
]
lookup_options = [
href_option,
Expand All @@ -263,6 +266,12 @@ def content() -> None:

content.add_command(list_command(decorators=list_options))
content.add_command(show_command(decorators=lookup_options))
content.add_command(
label_command(
decorators=lookup_options,
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
)
)
# create assumes "there exists an Artifact..."
# create is defined for package, modulemd and modulemd_defaults. The implications for modulemd
# and modulemd_defaults are generally not what the user expects. Therefore, leaving those two
Expand Down
17 changes: 17 additions & 0 deletions tests/scripts/pulp_file/test_label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@ expect_succ pulp file repository list --label-select "ainur=ulmo,istar=olorin"
test "$(echo "$OUTPUT" | jq length)" -eq 1
expect_succ pulp file repository list --label-select 'ainur=ulmo,!istar'
test "$(echo "$OUTPUT" | jq length)" -eq 0

# Test content label
if pulp debug has-plugin --name "core" --specifier ">=3.73.2"
then
echo "hi" > hi.txt
expect_succ pulp file content upload --file hi.txt --relative-path hi.txt --repository "$name"
expect_succ pulp file content list --sha256 "$(sha256sum hi.txt | cut -d' ' -f1)"
test "$(echo "$OUTPUT" | jq -r length)" -eq 1
content_href="$(echo "$OUTPUT" | jq -r .[0].pulp_href)"
expect_succ pulp file content label set --href "$content_href" --key "test" --value "value"
expect_succ pulp file content label show --href "$content_href" --key "test"
test "$OUTPUT" = "value"
expect_succ pulp file content list --label-select "test"
test "$(echo "$OUTPUT" | jq length)" -eq 1
expect_succ pulp file content label unset --href "$content_href" --key "test"
expect_fail pulp file content label show --href "$content_href" --key "test"
fi
Loading