Skip to content

Commit 5ed783f

Browse files
gerrod3mdellweg
authored andcommitted
Add content label commands
fixes: #1137
1 parent 244c288 commit 5ed783f

File tree

8 files changed

+72
-8
lines changed

8 files changed

+72
-8
lines changed

CHANGES/1137.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for content label commands, requires pulpcore 3.73.2 or later.

pulpcore/cli/ansible/content.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
PulpAnsibleRepositoryContext,
88
PulpAnsibleRoleContext,
99
)
10-
from pulp_glue.common.context import PulpContentContext, PulpRepositoryContext
10+
from pulp_glue.common.context import PluginRequirement, PulpContentContext, PulpRepositoryContext
1111
from pulp_glue.common.i18n import get_translation
1212
from pulp_glue.core.context import PulpArtifactContext
1313

1414
from pulp_cli.generic import (
1515
GroupOption,
1616
PulpCLIContext,
1717
href_option,
18+
label_command,
19+
label_select_option,
1820
list_command,
1921
parse_size_callback,
2022
pass_content_context,
@@ -114,6 +116,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
114116
help=_("Signing service used to create {entity}"),
115117
allowed_with_contexts=signature_context,
116118
),
119+
label_select_option,
117120
]
118121

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

166169
content.add_command(list_command(decorators=list_options))
167170
content.add_command(show_command(decorators=lookup_options))
171+
content.add_command(
172+
label_command(
173+
decorators=lookup_options,
174+
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
175+
)
176+
)
168177

169178

170179
# This is a mypy bug getting confused with positional args

pulpcore/cli/container/content.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import typing as t
33

44
import click
5-
from pulp_glue.common.context import PulpEntityContext
5+
from pulp_glue.common.context import PluginRequirement, PulpEntityContext
66
from pulp_glue.container.context import (
77
PulpContainerBlobContext,
88
PulpContainerManifestContext,
@@ -13,6 +13,8 @@
1313
GroupOption,
1414
PulpCLIContext,
1515
href_option,
16+
label_command,
17+
label_select_option,
1618
list_command,
1719
pass_pulp_context,
1820
pulp_group,
@@ -60,9 +62,10 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
6062
pulp_option(
6163
"--name-in", "name__in", multiple=True, allowed_with_contexts=(PulpContainerTagContext,)
6264
),
65+
label_select_option,
6366
]
6467

65-
show_options = [
68+
lookup_options = [
6669
pulp_option(
6770
"--digest",
6871
expose_value=False,
@@ -95,4 +98,10 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
9598
]
9699

97100
content.add_command(list_command(decorators=list_options))
98-
content.add_command(show_command(decorators=show_options))
101+
content.add_command(show_command(decorators=lookup_options))
102+
content.add_command(
103+
label_command(
104+
decorators=lookup_options,
105+
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
106+
)
107+
)

pulpcore/cli/container/repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
update_command,
3737
version_command,
3838
)
39-
from pulpcore.cli.container.content import show_options
39+
from pulpcore.cli.container.content import lookup_options as content_lookup_options
4040
from pulpcore.cli.core.generic import task_command
4141

4242
translation = get_translation(__package__)
@@ -133,8 +133,8 @@ def repository() -> None:
133133
repository.add_command(
134134
repository_content_command(
135135
contexts=contexts,
136-
add_decorators=show_options,
137-
remove_decorators=show_options,
136+
add_decorators=content_lookup_options,
137+
remove_decorators=content_lookup_options,
138138
allowed_with_contexts=container_context,
139139
base_default_plugin="container",
140140
base_default_type="container",

pulpcore/cli/file/content.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
chunk_size_option,
1212
create_command,
1313
href_option,
14+
label_command,
15+
label_select_option,
1416
list_command,
1517
pass_entity_context,
1618
pass_pulp_context,
@@ -109,11 +111,18 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
109111
decorators=[
110112
click.option("--relative-path"),
111113
click.option("--sha256"),
114+
label_select_option,
112115
]
113116
)
114117
)
115118
content.add_command(show_command(decorators=lookup_options))
116119
content.add_command(create_command(decorators=create_options))
120+
content.add_command(
121+
label_command(
122+
decorators=lookup_options,
123+
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
124+
)
125+
)
117126

118127

119128
@content.command()

pulpcore/cli/python/content.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
chunk_size_option,
1212
create_command,
1313
href_option,
14+
label_command,
15+
label_select_option,
1416
list_command,
1517
pass_entity_context,
1618
pass_pulp_context,
@@ -81,15 +83,23 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, /, content_type: str)
8183
needs_plugins=[PluginRequirement("core", specifier=">=3.56.1")],
8284
),
8385
]
86+
lookup_options = [href_option]
8487
content.add_command(
8588
list_command(
8689
decorators=[
8790
click.option("--filename", type=str),
91+
label_select_option,
8892
]
8993
)
9094
)
91-
content.add_command(show_command(decorators=[href_option]))
95+
content.add_command(show_command(decorators=lookup_options))
9296
content.add_command(create_command(decorators=create_options))
97+
content.add_command(
98+
label_command(
99+
decorators=lookup_options,
100+
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
101+
)
102+
)
93103

94104

95105
@content.command()

pulpcore/cli/rpm/content.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
exclude_field_option,
3030
field_option,
3131
href_option,
32+
label_command,
33+
label_select_option,
3234
list_command,
3335
pass_entity_context,
3436
pass_pulp_context,
@@ -240,6 +242,7 @@ def content() -> None:
240242
"--version-in", "version__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,)
241243
),
242244
pulp_option("--version-ne", "version__ne", allowed_with_contexts=(PulpRpmPackageContext,)),
245+
label_select_option,
243246
]
244247
lookup_options = [
245248
href_option,
@@ -263,6 +266,12 @@ def content() -> None:
263266

264267
content.add_command(list_command(decorators=list_options))
265268
content.add_command(show_command(decorators=lookup_options))
269+
content.add_command(
270+
label_command(
271+
decorators=lookup_options,
272+
need_plugins=[PluginRequirement("core", specifier=">=3.73.2")],
273+
)
274+
)
266275
# create assumes "there exists an Artifact..."
267276
# create is defined for package, modulemd and modulemd_defaults. The implications for modulemd
268277
# and modulemd_defaults are generally not what the user expects. Therefore, leaving those two

tests/scripts/pulp_file/test_label.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,20 @@ expect_succ pulp file repository list --label-select "ainur=ulmo,istar=olorin"
4545
test "$(echo "$OUTPUT" | jq length)" -eq 1
4646
expect_succ pulp file repository list --label-select 'ainur=ulmo,!istar'
4747
test "$(echo "$OUTPUT" | jq length)" -eq 0
48+
49+
# Test content label
50+
if pulp debug has-plugin --name "core" --specifier ">=3.73.2"
51+
then
52+
echo "hi" > hi.txt
53+
expect_succ pulp file content upload --file hi.txt --relative-path hi.txt --repository "$name"
54+
expect_succ pulp file content list --sha256 "$(sha256sum hi.txt | cut -d' ' -f1)"
55+
test "$(echo "$OUTPUT" | jq -r length)" -eq 1
56+
content_href="$(echo "$OUTPUT" | jq -r .[0].pulp_href)"
57+
expect_succ pulp file content label set --href "$content_href" --key "test" --value "value"
58+
expect_succ pulp file content label show --href "$content_href" --key "test"
59+
test "$OUTPUT" = "value"
60+
expect_succ pulp file content list --label-select "test"
61+
test "$(echo "$OUTPUT" | jq length)" -eq 1
62+
expect_succ pulp file content label unset --href "$content_href" --key "test"
63+
expect_fail pulp file content label show --href "$content_href" --key "test"
64+
fi

0 commit comments

Comments
 (0)