Skip to content

Commit 2a684a6

Browse files
gerrod3mdellweg
authored andcommitted
Add missing REST API filters to content list commands
- Introduce `content_filter_options` group in generic.py for common filters (repository_version, repository_version_added, repository_version_removed) - Add plugin-specific filters: Python (name, author, version, packagetype, filename), Container (digest, media-type), Ansible (pubkey-fingerprint-in), RPM (checksum-type, context, filename, expanded modulemd filters) - Add version constraints for newer Python filters (name/author contains) - Remove duplicate field/exclude-field options in RPM content - Add content filter tests to each plugin's test_content.sh Generated by: claude-4.6-opus Made-with: Cursor
1 parent 7fba181 commit 2a684a6

12 files changed

Lines changed: 248 additions & 23 deletions

File tree

CHANGES/+content-filters.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`.

src/pulp_cli/generic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,19 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: str | None
13371337
pulp_option("--repository-version", help=_("Search {entities} by repository version HREF")),
13381338
]
13391339

1340+
content_filter_options = [
1341+
label_select_option,
1342+
pulp_option("--repository-version", help=_("Search for {entities} in a repository version")),
1343+
pulp_option(
1344+
"--repository-version-added",
1345+
help=_("Search for {entities} added in a repository version"),
1346+
),
1347+
pulp_option(
1348+
"--repository-version-removed",
1349+
help=_("Search for {entities} removed from a repository version"),
1350+
),
1351+
]
1352+
13401353
_common_remote_options = [
13411354
click.option(
13421355
"--ca-cert",

src/pulpcore/cli/ansible/content.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
GroupOption,
1717
PulpCLIContext,
1818
chunk_size_callback,
19+
content_filter_options,
1920
href_option,
2021
label_command,
21-
label_select_option,
2222
list_command,
2323
pass_content_context,
2424
pass_pulp_context,
@@ -106,6 +106,13 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
106106
help=_("Public key fingerprint of the {entity}"),
107107
allowed_with_contexts=signature_context,
108108
),
109+
pulp_option(
110+
"--pubkey-fingerprint-in",
111+
"pubkey_fingerprint__in",
112+
multiple=True,
113+
help=_("Public key fingerprint of the {entity}"),
114+
allowed_with_contexts=signature_context,
115+
),
109116
pulp_option(
110117
"--collection",
111118
"signed_collection",
@@ -117,7 +124,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
117124
help=_("Signing service used to create {entity}"),
118125
allowed_with_contexts=signature_context,
119126
),
120-
label_select_option,
127+
*content_filter_options,
121128
]
122129

123130
lookup_options = [

src/pulpcore/cli/container/content.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from pulp_cli.generic import (
1414
GroupOption,
1515
PulpCLIContext,
16+
content_filter_options,
1617
href_option,
1718
label_command,
18-
label_select_option,
1919
list_command,
2020
pass_pulp_context,
2121
pulp_group,
@@ -58,12 +58,41 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
5858

5959

6060
list_options = [
61-
pulp_option("--media-type"),
61+
pulp_option(
62+
"--media-type",
63+
allowed_with_contexts=(PulpContainerManifestContext, PulpContainerTagContext),
64+
),
6265
pulp_option("--name", "name", allowed_with_contexts=(PulpContainerTagContext,)),
6366
pulp_option(
6467
"--name-in", "name__in", multiple=True, allowed_with_contexts=(PulpContainerTagContext,)
6568
),
66-
label_select_option,
69+
pulp_option(
70+
"--digest",
71+
allowed_with_contexts=(
72+
PulpContainerManifestContext,
73+
PulpContainerBlobContext,
74+
PulpContainerTagContext,
75+
),
76+
),
77+
pulp_option(
78+
"--digest-in",
79+
"digest__in",
80+
multiple=True,
81+
allowed_with_contexts=(PulpContainerManifestContext, PulpContainerBlobContext),
82+
),
83+
pulp_option(
84+
"--is-bootable",
85+
is_flag=True,
86+
default=None,
87+
allowed_with_contexts=(PulpContainerManifestContext,),
88+
),
89+
pulp_option(
90+
"--is-flatpak",
91+
is_flag=True,
92+
default=None,
93+
allowed_with_contexts=(PulpContainerManifestContext,),
94+
),
95+
*content_filter_options,
6796
]
6897

6998
lookup_options = [

src/pulpcore/cli/file/content.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from pulp_cli.generic import (
1111
PulpCLIContext,
1212
chunk_size_option,
13+
content_filter_options,
1314
create_command,
1415
href_option,
1516
label_command,
16-
label_select_option,
1717
list_command,
1818
pass_entity_context,
1919
pass_pulp_context,
@@ -112,7 +112,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
112112
decorators=[
113113
click.option("--relative-path"),
114114
click.option("--sha256"),
115-
label_select_option,
115+
*content_filter_options,
116116
]
117117
)
118118
)

src/pulpcore/cli/python/content.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from pulp_cli.generic import (
1616
PulpCLIContext,
1717
chunk_size_option,
18+
content_filter_options,
1819
create_command,
1920
href_option,
2021
label_command,
21-
label_select_option,
2222
list_command,
2323
load_json_callback,
2424
pass_entity_context,
@@ -158,10 +158,53 @@ def content() -> None:
158158
content.add_command(
159159
list_command(
160160
decorators=[
161+
pulp_option("--name", allowed_with_contexts=(PulpPythonContentContext,)),
162+
pulp_option(
163+
"--name-in",
164+
"name__in",
165+
multiple=True,
166+
allowed_with_contexts=(PulpPythonContentContext,),
167+
),
168+
pulp_option(
169+
"--name-contains",
170+
"name__contains",
171+
allowed_with_contexts=(PulpPythonContentContext,),
172+
needs_plugins=[PluginRequirement("python", specifier=">=3.25.0")],
173+
),
174+
pulp_option("--author", allowed_with_contexts=(PulpPythonContentContext,)),
175+
pulp_option(
176+
"--author-contains",
177+
"author__contains",
178+
allowed_with_contexts=(PulpPythonContentContext,),
179+
needs_plugins=[PluginRequirement("python", specifier=">=3.25.0")],
180+
),
181+
pulp_option("--packagetype", allowed_with_contexts=(PulpPythonContentContext,)),
182+
pulp_option(
183+
"--packagetype-in",
184+
"packagetype__in",
185+
multiple=True,
186+
allowed_with_contexts=(PulpPythonContentContext,),
187+
),
161188
pulp_option("--filename", allowed_with_contexts=(PulpPythonContentContext,)),
189+
pulp_option(
190+
"--filename-contains",
191+
"filename__contains",
192+
allowed_with_contexts=(PulpPythonContentContext,),
193+
),
194+
pulp_option("--version", allowed_with_contexts=(PulpPythonContentContext,)),
195+
pulp_option(
196+
"--version-gte",
197+
"version__gte",
198+
allowed_with_contexts=(PulpPythonContentContext,),
199+
),
200+
pulp_option(
201+
"--version-lte",
202+
"version__lte",
203+
allowed_with_contexts=(PulpPythonContentContext,),
204+
),
162205
pulp_option("--sha256"),
163-
label_select_option,
164206
package_option,
207+
*content_filter_options,
165208
]
166209
)
167210
)

src/pulpcore/cli/rpm/content.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
from pulp_cli.generic import (
2727
PulpCLIContext,
2828
chunk_size_option,
29+
content_filter_options,
2930
create_command,
30-
exclude_field_option,
31-
field_option,
3231
href_option,
3332
label_command,
34-
label_select_option,
3533
list_command,
3634
pass_entity_context,
3735
pass_pulp_context,
@@ -111,10 +109,10 @@ def content() -> None:
111109

112110

113111
list_options = [
114-
field_option,
115-
exclude_field_option,
116-
pulp_option("--repository-version"),
117-
pulp_option("--arch", allowed_with_contexts=(PulpRpmPackageContext,)),
112+
pulp_option(
113+
"--arch",
114+
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
115+
),
118116
pulp_option(
119117
"--arch-contains",
120118
"arch__contains",
@@ -125,7 +123,7 @@ def content() -> None:
125123
"--arch-in",
126124
"arch__in",
127125
multiple=True,
128-
allowed_with_contexts=(PulpRpmPackageContext,),
126+
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
129127
needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")],
130128
),
131129
pulp_option("--arch-ne", "arch__ne", allowed_with_contexts=(PulpRpmPackageContext,)),
@@ -135,11 +133,41 @@ def content() -> None:
135133
allowed_with_contexts=(PulpRpmPackageContext,),
136134
needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")],
137135
),
136+
pulp_option(
137+
"--checksum-type",
138+
"checksum_type",
139+
allowed_with_contexts=(PulpRpmPackageContext,),
140+
),
141+
pulp_option(
142+
"--checksum-type-in",
143+
"checksum_type__in",
144+
multiple=True,
145+
allowed_with_contexts=(PulpRpmPackageContext,),
146+
),
147+
pulp_option(
148+
"--checksum-type-ne",
149+
"checksum_type__ne",
150+
allowed_with_contexts=(PulpRpmPackageContext,),
151+
),
152+
pulp_option(
153+
"--context",
154+
allowed_with_contexts=(PulpRpmModulemdContext,),
155+
),
156+
pulp_option(
157+
"--context-in",
158+
"context__in",
159+
multiple=True,
160+
allowed_with_contexts=(PulpRpmModulemdContext,),
161+
),
138162
pulp_option("--epoch", allowed_with_contexts=(PulpRpmPackageContext,)),
139163
pulp_option(
140164
"--epoch-in", "epoch__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,)
141165
),
142166
pulp_option("--epoch-ne", "epoch__ne", allowed_with_contexts=(PulpRpmPackageContext,)),
167+
pulp_option(
168+
"--filename",
169+
allowed_with_contexts=(PulpRpmPackageContext,),
170+
),
143171
pulp_option("--id", allowed_with_contexts=(PulpRpmAdvisoryContext,)),
144172
pulp_option(
145173
"--id-in", "id__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,)
@@ -155,7 +183,7 @@ def content() -> None:
155183
pulp_option(
156184
"--name-contains",
157185
"name__contains",
158-
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
186+
allowed_with_contexts=(PulpRpmPackageContext,),
159187
needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")],
160188
),
161189
pulp_option(
@@ -167,12 +195,12 @@ def content() -> None:
167195
pulp_option(
168196
"--name-ne",
169197
"name__ne",
170-
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
198+
allowed_with_contexts=(PulpRpmPackageContext,),
171199
),
172200
pulp_option(
173201
"--name-startswith",
174202
"name__startswith",
175-
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
203+
allowed_with_contexts=(PulpRpmPackageContext,),
176204
needs_plugins=[PluginRequirement("rpm", specifier=">=3.20.0")],
177205
),
178206
pulp_option("--package-href", allowed_with_contexts=(PulpRpmPackageContext,)),
@@ -238,12 +266,18 @@ def content() -> None:
238266
"--type-in", "type__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,)
239267
),
240268
pulp_option("--type-ne", "type__ne", allowed_with_contexts=(PulpRpmAdvisoryContext,)),
241-
pulp_option("--version", allowed_with_contexts=(PulpRpmPackageContext,)),
242269
pulp_option(
243-
"--version-in", "version__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,)
270+
"--version",
271+
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
272+
),
273+
pulp_option(
274+
"--version-in",
275+
"version__in",
276+
multiple=True,
277+
allowed_with_contexts=(PulpRpmPackageContext, PulpRpmModulemdContext),
244278
),
245279
pulp_option("--version-ne", "version__ne", allowed_with_contexts=(PulpRpmPackageContext,)),
246-
label_select_option,
280+
*content_filter_options,
247281
]
248282
lookup_options = [
249283
href_option,

tests/scripts/pulp_ansible/test_content.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ expect_succ pulp ansible repository content remove --repository "cli_test_ansibl
8282
expect_succ pulp ansible repository content remove --repository "cli_test_ansible_content_repository" --href "$content2_href"
8383
expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository"
8484
test "$(echo "$OUTPUT" | jq -r length)" -eq "0"
85+
86+
# Test content list filter options
87+
expect_succ pulp ansible content list --name "posix"
88+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"
89+
expect_succ pulp ansible content list --namespace "ansible"
90+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"

tests/scripts/pulp_container/test_content.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ expect_succ pulp container repository content --type "tag" remove --repository "
5959
expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$blob_href"
6060
expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$manifest_href"
6161
expect_succ pulp container repository content add --repository "cli_test_container_content_repository" --href "$tag_href"
62+
63+
# Test content list filter options
64+
expect_succ pulp container content -t tag list --name "$tag_name"
65+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"
66+
67+
expect_succ pulp container content -t manifest list --digest "$manifest_digest"
68+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"
69+
70+
expect_succ pulp container content -t blob list --digest "$blob_digest"
71+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"

tests/scripts/pulp_file/test_content.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,18 @@ expect_succ pulp repository version list --content "$(jq -R '[.]' <<<"$content_h
7171
# Creating a new repository version from a different repository
7272
expect_succ pulp file repository create --name "cli_test_file_content_repository_2"
7373
expect_succ pulp file repository content modify --repository "cli_test_file_content_repository_2" --base-repository "cli_test_file_content_repository"
74+
75+
# Test content list filter options
76+
VERSION_HREF=$(pulp file repository version show --repository "cli_test_file_content_repository" | jq -r .pulp_href)
77+
78+
expect_succ pulp file content list --repository-version "$VERSION_HREF"
79+
test "$(echo "$OUTPUT" | jq -r length)" -gt "0"
80+
81+
expect_succ pulp file content list --repository-version-added "$VERSION_HREF"
82+
test "$(echo "$OUTPUT" | jq -r length)" -gt "0"
83+
84+
expect_succ pulp file content list --repository-version-removed "$VERSION_HREF"
85+
86+
FIRST_PATH=$(pulp file content list --repository-version "$VERSION_HREF" --limit 1 | jq -r '.[0].relative_path')
87+
expect_succ pulp file content list --relative-path "$FIRST_PATH"
88+
test "$(echo "$OUTPUT" | jq -r length)" -ge "1"

0 commit comments

Comments
 (0)