-
Notifications
You must be signed in to change notification settings - Fork 46
[PULP-1693] Add package blocklist to Python repos #1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added `blocklist` subcommand group to `pulp python repository` for managing blocklist entries (add, list, remove, show). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added `PulpPythonRepositoryBlocklistEntryContext` for `pulp_python>=3.29.0`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from pulp_glue.common.context import ( | ||
| EntityFieldDefinition, | ||
| PluginRequirement, | ||
| PulpEntityContext, | ||
| PulpRemoteContext, | ||
| PulpRepositoryContext, | ||
| ) | ||
|
|
@@ -14,6 +15,7 @@ | |
| PulpPythonContentContext, | ||
| PulpPythonProvenanceContext, | ||
| PulpPythonRemoteContext, | ||
| PulpPythonRepositoryBlocklistEntryContext, | ||
| PulpPythonRepositoryContext, | ||
| ) | ||
|
|
||
|
|
@@ -28,6 +30,7 @@ | |
| list_command, | ||
| lookup_callback, | ||
| name_option, | ||
| pass_entity_context, | ||
| pass_pulp_context, | ||
| pass_repository_context, | ||
| pulp_group, | ||
|
|
@@ -152,6 +155,74 @@ def repository() -> None: | |
| ) | ||
|
|
||
|
|
||
| @repository.group(needs_plugins=[PluginRequirement("python", specifier=">=3.29.0")]) | ||
| @pass_repository_context | ||
| @pass_pulp_context | ||
| @click.pass_context | ||
| def blocklist( | ||
| ctx: click.Context, | ||
| pulp_ctx: PulpCLIContext, | ||
| repository_ctx: PulpRepositoryContext, | ||
| /, | ||
| ) -> None: | ||
| """ | ||
| Manage blocklist entries for a Python repository. | ||
| """ | ||
| assert isinstance(repository_ctx, PulpPythonRepositoryContext) | ||
| ctx.obj = PulpPythonRepositoryBlocklistEntryContext(pulp_ctx, repository_ctx) | ||
|
|
||
|
|
||
| blocklist.add_command(list_command(decorators=nested_lookup_options)) | ||
| blocklist.add_command(show_command(decorators=nested_lookup_options + [href_option])) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look right. How do you identify a blocklist on a repository? Can a repository have more than one blocklist? |
||
| blocklist.add_command( | ||
| destroy_command(name="remove", decorators=nested_lookup_options + [href_option]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also looks like suboptimal ux. |
||
| ) | ||
|
|
||
|
|
||
| @blocklist.command(name="add") | ||
| @repository_href_option | ||
| @repository_lookup_option | ||
| @click.option( | ||
| "--name", | ||
| "pkg_name", | ||
| default=None, | ||
| help=_("Package name to block. Required when 'filename' is not provided."), | ||
| ) | ||
| @click.option( | ||
| "--version", | ||
| "pkg_version", | ||
| default=None, | ||
| help=_("Exact version to block. Only used when 'name' is set."), | ||
| ) | ||
| @click.option( | ||
| "--filename", | ||
| "pkg_filename", | ||
| default=None, | ||
| help=_("Exact filename to block. Required when 'name' is not provided."), | ||
| ) | ||
| @pass_entity_context | ||
| @pass_pulp_context | ||
| def blocklist_add( | ||
| pulp_ctx: PulpCLIContext, | ||
| entity_ctx: PulpEntityContext, | ||
| /, | ||
| pkg_name: str | None, | ||
| pkg_version: str | None, | ||
| pkg_filename: str | None, | ||
| ) -> None: | ||
| """Add a blocklist entry to the repository.""" | ||
| assert isinstance(entity_ctx, PulpPythonRepositoryBlocklistEntryContext) | ||
| body: dict[str, t.Any] = {} | ||
| if pkg_name: | ||
| body["name"] = pkg_name | ||
| if pkg_version: | ||
| body["version"] = pkg_version | ||
| if pkg_filename: | ||
| body["filename"] = pkg_filename | ||
| result = entity_ctx.create(body=body) | ||
| pulp_ctx.output_result(result) | ||
|
|
||
|
|
||
| @repository.command() | ||
| @name_option | ||
| @href_option | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eu | ||
| # shellcheck source=tests/scripts/config.source | ||
| . "$(dirname "$(dirname "$(realpath "$0")")")"/config.source | ||
|
|
||
| pulp debug has-plugin --name "python" --specifier ">=3.29.0" || exit 23 | ||
|
|
||
| cleanup() { | ||
| pulp python repository destroy --name "cli_test_python_blocklist" || true | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| expect_succ pulp python repository create --name "cli_test_python_blocklist" | ||
|
|
||
| # Test adding a blocklist entry by package name + version | ||
| expect_succ pulp python repository blocklist add --repository "cli_test_python_blocklist" --name "pkg" --version "1.0" | ||
| test "$(echo "$OUTPUT" | jq -r '.name')" = "pkg" | ||
| test "$(echo "$OUTPUT" | jq -r '.version')" = "1.0" | ||
| test "$(echo "$OUTPUT" | jq -r '.filename')" = "null" | ||
| ENTRY_HREF="$(echo "$OUTPUT" | jq -r '.pulp_href')" | ||
|
|
||
| # Test listing blocklist entries | ||
| expect_succ pulp python repository blocklist list --repository "cli_test_python_blocklist" | ||
| expect_succ test "$(echo "$OUTPUT" | jq -r '.|length')" = "1" | ||
|
|
||
| # Test showing a specific blocklist entry | ||
| expect_succ pulp python repository blocklist show --repository "cli_test_python_blocklist" --href "$ENTRY_HREF" | ||
| expect_succ test "$(echo "$OUTPUT" | jq -r '.name')" = "pkg" | ||
|
|
||
| # Test removing a blocklist entry | ||
| expect_succ pulp python repository blocklist remove --repository "cli_test_python_blocklist" --href "$ENTRY_HREF" | ||
| expect_succ pulp python repository blocklist list --repository "cli_test_python_blocklist" | ||
| expect_succ test "$(echo "$OUTPUT" | jq -r '.|length')" = "0" | ||
|
|
||
| expect_succ pulp python repository destroy --name "cli_test_python_blocklist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the "repository" in there adds any information or helps distinguishing things.