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/+content-filters.feature
Original file line number Diff line number Diff line change
@@ -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`.
13 changes: 13 additions & 0 deletions src/pulp_cli/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions src/pulpcore/cli/ansible/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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 = [
Expand Down
35 changes: 32 additions & 3 deletions src/pulpcore/cli/container/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions src/pulpcore/cli/file/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
]
)
)
Expand Down
47 changes: 45 additions & 2 deletions src/pulpcore/cli/python/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
]
)
)
Expand Down
62 changes: 48 additions & 14 deletions src/pulpcore/cli/rpm/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,10 +109,10 @@ def content() -> None:


list_options = [
field_option,
exclude_field_option,
Comment on lines -114 to -115
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we remove these?
I guess you wanted to add them to the generic list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already specified on the list_command() generic. They are decorated on the callback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So they were superfluous already.
👍

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",
Expand All @@ -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,)),
Expand All @@ -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,)
Expand All @@ -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(
Expand All @@ -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,)),
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests/scripts/pulp_ansible/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 10 additions & 0 deletions tests/scripts/pulp_container/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions tests/scripts/pulp_file/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading
Loading