forked from pulp/pulp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes: pulp#352
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added commands for CRUD RBAC Content Guards. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import gettext | ||
from typing import List, Optional | ||
|
||
import click | ||
|
||
from pulpcore.cli.common.context import ( | ||
PluginRequirement, | ||
PulpContext, | ||
pass_entity_context, | ||
pass_pulp_context, | ||
) | ||
from pulpcore.cli.common.generic import ( | ||
create_command, | ||
destroy_command, | ||
href_option, | ||
list_command, | ||
load_json_callback, | ||
name_option, | ||
show_command, | ||
update_command, | ||
) | ||
from pulpcore.cli.core.context import PulpContentGuardContext, PulpRbacContentGuardContext | ||
|
||
_ = gettext.gettext | ||
|
||
|
||
@click.group() | ||
@pass_pulp_context | ||
@click.pass_context | ||
def content_guard(ctx: click.Context, pulp_ctx: PulpContext) -> None: | ||
ctx.obj = PulpContentGuardContext(pulp_ctx) | ||
|
||
|
||
create_options = [click.option("--name", required=True), click.option("--description")] | ||
filter_options = [click.option("--name")] | ||
lookup_options = [name_option, href_option] | ||
|
||
content_guard.add_command(list_command(decorators=filter_options)) | ||
|
||
|
||
@content_guard.group() | ||
@pass_pulp_context | ||
@click.pass_context | ||
def rbac(ctx: click.Context, pulp_ctx: PulpContext) -> None: | ||
pulp_ctx.needs_plugin(PluginRequirement("core", "3.15.0.dev")) | ||
ctx.obj = PulpRbacContentGuardContext(pulp_ctx) | ||
|
||
|
||
rbac.add_command(list_command(decorators=filter_options)) | ||
rbac.add_command(create_command(decorators=create_options)) | ||
rbac.add_command(show_command(decorators=lookup_options)) | ||
rbac.add_command(update_command(decorators=lookup_options)) | ||
rbac.add_command(destroy_command(decorators=lookup_options)) | ||
|
||
|
||
@rbac.command() | ||
@name_option | ||
@href_option | ||
@click.option( | ||
"--group", | ||
"groups", | ||
help=_("Groups to remove download permission from. Can be specified multiple times."), | ||
multiple=True, | ||
) | ||
@click.option( | ||
"--user", | ||
"users", | ||
help=_("Users to remove download permission from. Can be specified multiple times."), | ||
multiple=True, | ||
) | ||
@pass_entity_context | ||
@pass_pulp_context | ||
def assign( | ||
pulp_ctx: PulpContext, | ||
guard_ctx: PulpRbacContentGuardContext, | ||
users: Optional[List[str]], | ||
groups: Optional[List[str]], | ||
) -> None: | ||
href = guard_ctx.entity["pulp_href"] | ||
result = guard_ctx.assign(href=href, users=users, groups=groups) | ||
pulp_ctx.output_result(result) | ||
|
||
|
||
@rbac.command() | ||
@name_option | ||
@href_option | ||
@click.option( | ||
"--group", | ||
"groups", | ||
help=_("Groups to remove download permission from. Can be specified multiple times."), | ||
multiple=True, | ||
) | ||
@click.option( | ||
"--user", | ||
"users", | ||
help=_("Users to remove download permission from. Can be specified multiple times."), | ||
multiple=True, | ||
) | ||
@pass_entity_context | ||
@pass_pulp_context | ||
def remove( | ||
pulp_ctx: PulpContext, | ||
guard_ctx: PulpRbacContentGuardContext, | ||
users: Optional[List[str]], | ||
groups: Optional[List[str]], | ||
) -> None: | ||
href = guard_ctx.entity["pulp_href"] | ||
result = guard_ctx.remove(href=href, users=users, groups=groups) | ||
pulp_ctx.output_result(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# shellcheck source=tests/scripts/config.source | ||
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source | ||
|
||
pulp debug has-plugin --name "core" --min-version "3.15.1" || exit 3 | ||
|
||
cleanup() { | ||
pulp content-guard rbac destroy --name "cli_test_guard" || true | ||
pulp group destroy --name "cli_test_group" || true | ||
} | ||
trap cleanup EXIT | ||
|
||
expect_succ pulp content-guard rbac create --name "cli_test_guard" | ||
expect_succ pulp content-guard list | ||
test "$(echo "$OUTPUT" | jq -r length)" -gt "0" | ||
expect_succ pulp content-guard rbac list --name "cli_test_guard" | ||
test "$(echo "$OUTPUT" | jq -r length)" -eq "1" | ||
expect_succ pulp content-guard rbac show --name "cli_test_guard" | ||
|
||
expect_succ pulp group create --name "cli_test_group" | ||
expect_succ pulp content-guard rbac assign --name "cli_test_guard" --group "cli_test_group" | ||
test "$(echo "$OUTPUT" | jq -r '.groups' | jq -r length)" -eq "1" | ||
expect_succ pulp content-guard rbac remove --name "cli_test_guard" --user "admin" --group "cli_test_group" | ||
test "$(echo "$OUTPUT" | jq -r '.users' | jq -r length)" -eq "0" | ||
test "$(echo "$OUTPUT" | jq -r '.groups' | jq -r length)" -eq "0" |