diff --git a/CHANGES/+content-filters.feature b/CHANGES/+content-filters.feature new file mode 100644 index 000000000..a5b61da40 --- /dev/null +++ b/CHANGES/+content-filters.feature @@ -0,0 +1 @@ +Added missing REST API filters to content list commands across all plugins and grouped common content filters (`repository_version`, `repository_version_added`, `repository_version_removed`) into reusable `content_filter_options`. diff --git a/src/pulp_cli/generic.py b/src/pulp_cli/generic.py index 3dcaf4c28..f9c940442 100644 --- a/src/pulp_cli/generic.py +++ b/src/pulp_cli/generic.py @@ -1337,6 +1337,19 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: str | None pulp_option("--repository-version", help=_("Search {entities} by repository version HREF")), ] +content_filter_options = [ + label_select_option, + pulp_option("--repository-version", help=_("Search for {entities} in a repository version")), + pulp_option( + "--repository-version-added", + help=_("Search for {entities} added in a repository version"), + ), + pulp_option( + "--repository-version-removed", + help=_("Search for {entities} removed from a repository version"), + ), +] + _common_remote_options = [ click.option( "--ca-cert", diff --git a/src/pulpcore/cli/ansible/content.py b/src/pulpcore/cli/ansible/content.py index 97ab0d045..cd475a2d2 100644 --- a/src/pulpcore/cli/ansible/content.py +++ b/src/pulpcore/cli/ansible/content.py @@ -16,9 +16,9 @@ GroupOption, PulpCLIContext, chunk_size_callback, + content_filter_options, href_option, label_command, - label_select_option, list_command, pass_content_context, pass_pulp_context, @@ -106,6 +106,13 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str) help=_("Public key fingerprint of the {entity}"), allowed_with_contexts=signature_context, ), + pulp_option( + "--pubkey-fingerprint-in", + "pubkey_fingerprint__in", + multiple=True, + help=_("Public key fingerprint of the {entity}"), + allowed_with_contexts=signature_context, + ), pulp_option( "--collection", "signed_collection", @@ -117,7 +124,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, + *content_filter_options, ] lookup_options = [ diff --git a/src/pulpcore/cli/container/content.py b/src/pulpcore/cli/container/content.py index 87e40ed09..7f9ba4b50 100644 --- a/src/pulpcore/cli/container/content.py +++ b/src/pulpcore/cli/container/content.py @@ -13,9 +13,9 @@ from pulp_cli.generic import ( GroupOption, PulpCLIContext, + content_filter_options, href_option, label_command, - label_select_option, list_command, pass_pulp_context, pulp_group, @@ -58,12 +58,41 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str) list_options = [ - pulp_option("--media-type"), + pulp_option( + "--media-type", + allowed_with_contexts=(PulpContainerManifestContext, PulpContainerTagContext), + ), pulp_option("--name", "name", allowed_with_contexts=(PulpContainerTagContext,)), pulp_option( "--name-in", "name__in", multiple=True, allowed_with_contexts=(PulpContainerTagContext,) ), - label_select_option, + pulp_option( + "--digest", + allowed_with_contexts=( + PulpContainerManifestContext, + PulpContainerBlobContext, + PulpContainerTagContext, + ), + ), + pulp_option( + "--digest-in", + "digest__in", + multiple=True, + allowed_with_contexts=(PulpContainerManifestContext, PulpContainerBlobContext), + ), + pulp_option( + "--is-bootable", + is_flag=True, + default=None, + allowed_with_contexts=(PulpContainerManifestContext,), + ), + pulp_option( + "--is-flatpak", + is_flag=True, + default=None, + allowed_with_contexts=(PulpContainerManifestContext,), + ), + *content_filter_options, ] lookup_options = [ diff --git a/src/pulpcore/cli/file/content.py b/src/pulpcore/cli/file/content.py index c936afb0b..9f406ca2d 100644 --- a/src/pulpcore/cli/file/content.py +++ b/src/pulpcore/cli/file/content.py @@ -10,10 +10,10 @@ from pulp_cli.generic import ( PulpCLIContext, chunk_size_option, + content_filter_options, create_command, href_option, label_command, - label_select_option, list_command, pass_entity_context, pass_pulp_context, @@ -112,7 +112,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str) decorators=[ click.option("--relative-path"), click.option("--sha256"), - label_select_option, + *content_filter_options, ] ) ) diff --git a/src/pulpcore/cli/python/content.py b/src/pulpcore/cli/python/content.py index 0320f25d4..df68602ae 100644 --- a/src/pulpcore/cli/python/content.py +++ b/src/pulpcore/cli/python/content.py @@ -15,10 +15,10 @@ from pulp_cli.generic import ( PulpCLIContext, chunk_size_option, + content_filter_options, create_command, href_option, label_command, - label_select_option, list_command, load_json_callback, pass_entity_context, @@ -158,10 +158,53 @@ def content() -> None: content.add_command( list_command( decorators=[ + pulp_option("--name", allowed_with_contexts=(PulpPythonContentContext,)), + pulp_option( + "--name-in", + "name__in", + multiple=True, + allowed_with_contexts=(PulpPythonContentContext,), + ), + pulp_option( + "--name-contains", + "name__contains", + allowed_with_contexts=(PulpPythonContentContext,), + needs_plugins=[PluginRequirement("python", specifier=">=3.25.0")], + ), + pulp_option("--author", allowed_with_contexts=(PulpPythonContentContext,)), + pulp_option( + "--author-contains", + "author__contains", + allowed_with_contexts=(PulpPythonContentContext,), + needs_plugins=[PluginRequirement("python", specifier=">=3.25.0")], + ), + pulp_option("--packagetype", allowed_with_contexts=(PulpPythonContentContext,)), + pulp_option( + "--packagetype-in", + "packagetype__in", + multiple=True, + allowed_with_contexts=(PulpPythonContentContext,), + ), pulp_option("--filename", allowed_with_contexts=(PulpPythonContentContext,)), + pulp_option( + "--filename-contains", + "filename__contains", + allowed_with_contexts=(PulpPythonContentContext,), + ), + pulp_option("--version", allowed_with_contexts=(PulpPythonContentContext,)), + pulp_option( + "--version-gte", + "version__gte", + allowed_with_contexts=(PulpPythonContentContext,), + ), + pulp_option( + "--version-lte", + "version__lte", + allowed_with_contexts=(PulpPythonContentContext,), + ), pulp_option("--sha256"), - label_select_option, package_option, + *content_filter_options, ] ) ) diff --git a/src/pulpcore/cli/rpm/content.py b/src/pulpcore/cli/rpm/content.py index 7954ee4ac..fc9cc1c03 100644 --- a/src/pulpcore/cli/rpm/content.py +++ b/src/pulpcore/cli/rpm/content.py @@ -26,12 +26,10 @@ from pulp_cli.generic import ( PulpCLIContext, chunk_size_option, + content_filter_options, create_command, - exclude_field_option, - field_option, href_option, label_command, - label_select_option, list_command, pass_entity_context, pass_pulp_context, @@ -111,10 +109,10 @@ def content() -> None: list_options = [ - field_option, - exclude_field_option, - pulp_option("--repository-version"), - pulp_option("--arch", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--arch", + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + ), pulp_option( "--arch-contains", "arch__contains", @@ -125,7 +123,7 @@ def content() -> None: "--arch-in", "arch__in", multiple=True, - allowed_with_contexts=(PulpRpmPackageContext,), + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], ), pulp_option("--arch-ne", "arch__ne", allowed_with_contexts=(PulpRpmPackageContext,)), @@ -135,11 +133,41 @@ def content() -> None: allowed_with_contexts=(PulpRpmPackageContext,), needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], ), + pulp_option( + "--checksum-type", + "checksum_type", + allowed_with_contexts=(PulpRpmPackageContext,), + ), + pulp_option( + "--checksum-type-in", + "checksum_type__in", + multiple=True, + allowed_with_contexts=(PulpRpmPackageContext,), + ), + pulp_option( + "--checksum-type-ne", + "checksum_type__ne", + allowed_with_contexts=(PulpRpmPackageContext,), + ), + pulp_option( + "--context", + allowed_with_contexts=(PulpRpmModulemdContext,), + ), + pulp_option( + "--context-in", + "context__in", + multiple=True, + allowed_with_contexts=(PulpRpmModulemdContext,), + ), pulp_option("--epoch", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( "--epoch-in", "epoch__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) ), pulp_option("--epoch-ne", "epoch__ne", allowed_with_contexts=(PulpRpmPackageContext,)), + pulp_option( + "--filename", + allowed_with_contexts=(PulpRpmPackageContext,), + ), pulp_option("--id", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( "--id-in", "id__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,) @@ -155,7 +183,7 @@ def content() -> None: pulp_option( "--name-contains", "name__contains", - allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + allowed_with_contexts=(PulpRpmPackageContext,), needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], ), pulp_option( @@ -167,12 +195,12 @@ def content() -> None: pulp_option( "--name-ne", "name__ne", - allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + allowed_with_contexts=(PulpRpmPackageContext,), ), pulp_option( "--name-startswith", "name__startswith", - allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + allowed_with_contexts=(PulpRpmPackageContext,), needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")], ), pulp_option("--package-href", allowed_with_contexts=(PulpRpmPackageContext,)), @@ -238,12 +266,18 @@ def content() -> None: "--type-in", "type__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,) ), pulp_option("--type-ne", "type__ne", allowed_with_contexts=(PulpRpmAdvisoryContext,)), - pulp_option("--version", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( - "--version-in", "version__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) + "--version", + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), + ), + pulp_option( + "--version-in", + "version__in", + multiple=True, + allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext), ), pulp_option("--version-ne", "version__ne", allowed_with_contexts=(PulpRpmPackageContext,)), - label_select_option, + *content_filter_options, ] lookup_options = [ href_option, diff --git a/tests/scripts/pulp_ansible/test_content.sh b/tests/scripts/pulp_ansible/test_content.sh index a404d18c0..83414def9 100755 --- a/tests/scripts/pulp_ansible/test_content.sh +++ b/tests/scripts/pulp_ansible/test_content.sh @@ -82,3 +82,9 @@ expect_succ pulp ansible repository content remove --repository "cli_test_ansibl expect_succ pulp ansible repository content remove --repository "cli_test_ansible_content_repository" --href "$content2_href" expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository" test "$(echo "$OUTPUT" | jq -r length)" -eq "0" + +# Test content list filter options +expect_succ pulp ansible content list --name "posix" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" +expect_succ pulp ansible content list --namespace "ansible" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" diff --git a/tests/scripts/pulp_container/test_content.sh b/tests/scripts/pulp_container/test_content.sh index 6e39cd17b..a59f79f0d 100755 --- a/tests/scripts/pulp_container/test_content.sh +++ b/tests/scripts/pulp_container/test_content.sh @@ -59,3 +59,13 @@ expect_succ pulp container repository content --type "tag" remove --repository " expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$blob_href" expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$manifest_href" expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$tag_href" + +# Test content list filter options +expect_succ pulp container content -t tag list --name "$tag_name" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +expect_succ pulp container content -t manifest list --digest "$manifest_digest" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +expect_succ pulp container content -t blob list --digest "$blob_digest" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" diff --git a/tests/scripts/pulp_file/test_content.sh b/tests/scripts/pulp_file/test_content.sh index 93f42c98e..67fa3c0f9 100755 --- a/tests/scripts/pulp_file/test_content.sh +++ b/tests/scripts/pulp_file/test_content.sh @@ -71,3 +71,18 @@ expect_succ pulp repository version list --content "$(jq -R '[.]' <<<"$content_h # Creating a new repository version from a different repository expect_succ pulp file repository create --name "cli_test_file_content_repository_2" expect_succ pulp file repository content modify --repository "cli_test_file_content_repository_2" --base-repository "cli_test_file_content_repository" + +# Test content list filter options +VERSION_HREF=$(pulp file repository version show --repository "cli_test_file_content_repository" | jq -r .pulp_href) + +expect_succ pulp file content list --repository-version "$VERSION_HREF" +test "$(echo "$OUTPUT" | jq -r length)" -gt "0" + +expect_succ pulp file content list --repository-version-added "$VERSION_HREF" +test "$(echo "$OUTPUT" | jq -r length)" -gt "0" + +expect_succ pulp file content list --repository-version-removed "$VERSION_HREF" + +FIRST_PATH=$(pulp file content list --repository-version "$VERSION_HREF" --limit 1 | jq -r '.[0].relative_path') +expect_succ pulp file content list --relative-path "$FIRST_PATH" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" diff --git a/tests/scripts/pulp_python/test_content.sh b/tests/scripts/pulp_python/test_content.sh index 2d9b6ce37..b05a67c46 100755 --- a/tests/scripts/pulp_python/test_content.sh +++ b/tests/scripts/pulp_python/test_content.sh @@ -31,6 +31,39 @@ then expect_succ pulp python content create --file-url "$file_url" --relative-path "shelf-reader-0.1.tar.gz" fi +# Test content list filter options +expect_succ pulp python content list --name "shelf-reader" +test "$(echo "$OUTPUT" | jq -r length)" -gt "0" +test "$(echo "$OUTPUT" | jq -r '.[0].name')" = "shelf-reader" + +expect_succ pulp python content list --name-in "shelf-reader" +test "$(echo "$OUTPUT" | jq -r length)" -gt "0" + +if pulp debug has-plugin --name "python" --specifier ">=3.25.0" +then + expect_succ pulp python content list --name-contains "shelf" + test "$(echo "$OUTPUT" | jq -r length)" -gt "0" +fi + +expect_succ pulp python content list --name "shelf-reader" --version "0.1" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +expect_succ pulp python content list --name "shelf-reader" --version-gte "0.1" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +expect_succ pulp python content list --name "shelf-reader" --packagetype "sdist" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +expect_succ pulp python content list --filename-contains "shelf-reader" +test "$(echo "$OUTPUT" | jq -r length)" -ge "1" + +FIRST_AUTHOR=$(echo "$OUTPUT" | jq -r '.[0].author') +if [ -n "$FIRST_AUTHOR" ] && [ "$FIRST_AUTHOR" != "null" ] +then + expect_succ pulp python content list --author "$FIRST_AUTHOR" + test "$(echo "$OUTPUT" | jq -r length)" -ge "1" +fi + expect_succ pulp python repository create --name "cli_test_python_content_repository" HREF="$(echo "$OUTPUT" | jq -r '.pulp_href')" expect_succ pulp python repository content add --repository "cli_test_python_content_repository" --sha256 "$sha256" diff --git a/tests/scripts/pulp_rpm/test_content.sh b/tests/scripts/pulp_rpm/test_content.sh index 9df802967..1c6e883ca 100755 --- a/tests/scripts/pulp_rpm/test_content.sh +++ b/tests/scripts/pulp_rpm/test_content.sh @@ -153,3 +153,37 @@ expect_succ test "$(echo "${OUTPUT}" | jq -r 'length')" -eq 2 # test upload for advisory, package-upload is tested at the start expect_succ pulp rpm content -t advisory upload --file "${TEST_ADVISORY}" + +# Test content list filter options +expect_succ pulp rpm content -t package list --repository-version "${VERSION_HREF}" --limit 1 +FIRST_PKG_NAME=$(echo "${OUTPUT}" | jq -r '.[0].name') + +expect_succ pulp rpm content -t package list --name "${FIRST_PKG_NAME}" +test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" + +expect_succ pulp rpm content -t package list --repository-version "${VERSION_HREF}" --checksum-type "sha256" --limit 5 +test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" + +# Test modulemd filters +expect_succ pulp rpm content -t modulemd list --repository-version "${VERSION_HREF}" +test "$(echo "${OUTPUT}" | jq -r length)" -gt "0" +MOD_NAME=$(echo "${OUTPUT}" | jq -r '.[0].name') +MOD_VERSION=$(echo "${OUTPUT}" | jq -r '.[0].version') +MOD_CONTEXT=$(echo "${OUTPUT}" | jq -r '.[0].context') +MOD_ARCH=$(echo "${OUTPUT}" | jq -r '.[0].arch') + +expect_succ pulp rpm content -t modulemd list --name "${MOD_NAME}" --version "${MOD_VERSION}" +test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" +expect_succ pulp rpm content -t modulemd list --name "${MOD_NAME}" --context "${MOD_CONTEXT}" +test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" +expect_succ pulp rpm content -t modulemd list --name "${MOD_NAME}" --arch "${MOD_ARCH}" +test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" + +# Test advisory filters +expect_succ pulp rpm content -t advisory list --repository-version "${VERSION_HREF}" --limit 1 +if test "$(echo "${OUTPUT}" | jq -r length)" -gt "0" +then + ADV_ID=$(echo "${OUTPUT}" | jq -r '.[0].id') + expect_succ pulp rpm content -t advisory list --id "${ADV_ID}" + test "$(echo "${OUTPUT}" | jq -r length)" -ge "1" +fi