diff --git a/CHANGES/1137.feature b/CHANGES/1137.feature new file mode 100644 index 000000000..7c9da47eb --- /dev/null +++ b/CHANGES/1137.feature @@ -0,0 +1 @@ +Add support for content label commands, requires pulpcore 3.73.2 or later. diff --git a/pulpcore/cli/ansible/content.py b/pulpcore/cli/ansible/content.py index 536dc3ce5..b3b5bb4d6 100644 --- a/pulpcore/cli/ansible/content.py +++ b/pulpcore/cli/ansible/content.py @@ -7,7 +7,7 @@ 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 @@ -15,6 +15,8 @@ GroupOption, PulpCLIContext, href_option, + label_command, + label_select_option, list_command, parse_size_callback, pass_content_context, @@ -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 = [ @@ -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 diff --git a/pulpcore/cli/container/content.py b/pulpcore/cli/container/content.py index 59bd0b54e..37b676d47 100644 --- a/pulpcore/cli/container/content.py +++ b/pulpcore/cli/container/content.py @@ -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, @@ -13,6 +13,8 @@ GroupOption, PulpCLIContext, href_option, + label_command, + label_select_option, list_command, pass_pulp_context, pulp_group, @@ -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, @@ -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")], + ) +) diff --git a/pulpcore/cli/container/repository.py b/pulpcore/cli/container/repository.py index 358ef8e52..83d2f08cf 100644 --- a/pulpcore/cli/container/repository.py +++ b/pulpcore/cli/container/repository.py @@ -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__) @@ -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", diff --git a/pulpcore/cli/file/content.py b/pulpcore/cli/file/content.py index 5c2f51fa4..d11e437e6 100644 --- a/pulpcore/cli/file/content.py +++ b/pulpcore/cli/file/content.py @@ -11,6 +11,8 @@ chunk_size_option, create_command, href_option, + label_command, + label_select_option, list_command, pass_entity_context, pass_pulp_context, @@ -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() diff --git a/pulpcore/cli/python/content.py b/pulpcore/cli/python/content.py index a604dd1da..dda42625f 100644 --- a/pulpcore/cli/python/content.py +++ b/pulpcore/cli/python/content.py @@ -11,6 +11,8 @@ chunk_size_option, create_command, href_option, + label_command, + label_select_option, list_command, pass_entity_context, pass_pulp_context, @@ -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() diff --git a/pulpcore/cli/rpm/content.py b/pulpcore/cli/rpm/content.py index 7fb6011f4..9dbc607a9 100644 --- a/pulpcore/cli/rpm/content.py +++ b/pulpcore/cli/rpm/content.py @@ -29,6 +29,8 @@ exclude_field_option, field_option, href_option, + label_command, + label_select_option, list_command, pass_entity_context, pass_pulp_context, @@ -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, @@ -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 diff --git a/tests/scripts/pulp_file/test_label.sh b/tests/scripts/pulp_file/test_label.sh index 22256de43..965006f48 100755 --- a/tests/scripts/pulp_file/test_label.sh +++ b/tests/scripts/pulp_file/test_label.sh @@ -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 \ No newline at end of file