Skip to content

Commit

Permalink
Add role commands
Browse files Browse the repository at this point in the history
fixes #31
  • Loading branch information
mdellweg committed Oct 19, 2023
1 parent 7b79786 commit 055f101
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES/31.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for managing roles (RBAC) on gem related objects.
4 changes: 2 additions & 2 deletions lower_bounds_constraints.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pulp-cli==0.19.0
pulp-glue==0.19.0
pulp-cli==0.20.0
pulp-glue==0.20.0
4 changes: 4 additions & 0 deletions pulp-glue-gem/pulp_glue/gem/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PulpGemDistributionContext(PulpDistributionContext):
HREF = "gem_gem_distribution_href"
ID_PREFIX = "distributions_gem_gem"
NEEDS_PLUGINS = [PluginRequirement("gem")]
CAPABILITIES = {"roles": [PluginRequirement("gem", specifier=">=0.4.0.dev")]}

def preprocess_body(self, body: EntityDefinition) -> EntityDefinition:
body = super().preprocess_body(body)
Expand All @@ -49,6 +50,7 @@ class PulpGemPublicationContext(PulpPublicationContext):
HREF = "gem_gem_publication_href"
ID_PREFIX = "publications_gem_gem"
NEEDS_PLUGINS = [PluginRequirement("gem")]
CAPABILITIES = {"roles": [PluginRequirement("gem", specifier=">=0.4.0.dev")]}

def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition:
body = super().preprocess_entity(body, partial=partial)
Expand All @@ -67,6 +69,7 @@ class PulpGemRemoteContext(PulpRemoteContext):
HREF = "gem_gem_remote_href"
ID_PREFIX = "remotes_gem_gem"
NEEDS_PLUGINS = [PluginRequirement("gem")]
CAPABILITIES = {"roles": [PluginRequirement("gem", specifier=">=0.4.0.dev")]}


class PulpGemRepositoryVersionContext(PulpRepositoryVersionContext):
Expand All @@ -85,3 +88,4 @@ class PulpGemRepositoryContext(PulpRepositoryContext):
VERSION_CONTEXT = PulpGemRepositoryVersionContext
NEEDS_PLUGINS = [PluginRequirement("gem")]
NULLABLES = PulpRepositoryContext.NULLABLES | {"remote"}
CAPABILITIES = {"roles": [PluginRequirement("gem", specifier=">=0.4.0.dev")]}
2 changes: 1 addition & 1 deletion pulp-glue-gem/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
packages=plugin_packages,
package_data={"": ["py.typed"]},
python_requires=">=3.6",
install_requires=["pulp-glue>=0.19.0"],
install_requires=["pulp-glue>=0.20.0"],
license="GPLv2+",
classifiers=[
"Development Status :: 4 - Beta",
Expand Down
2 changes: 2 additions & 0 deletions pulpcore/cli/gem/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pulp_group,
pulp_labels_option,
resource_option,
role_command,
show_command,
update_command,
)
Expand Down Expand Up @@ -92,3 +93,4 @@ def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, distribution_type
)
distribution.add_command(destroy_command(decorators=lookup_options))
distribution.add_command(label_command(decorators=nested_lookup_options))
distribution.add_command(role_command(decorators=nested_lookup_options))
2 changes: 2 additions & 0 deletions pulpcore/cli/gem/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
publication_filter_options,
pulp_group,
resource_option,
role_command,
show_command,
)

Expand Down Expand Up @@ -55,3 +56,4 @@ def publication(ctx: click.Context, pulp_ctx: PulpCLIContext, publication_type:
publication.add_command(show_command(decorators=lookup_options))
publication.add_command(create_command(decorators=create_options))
publication.add_command(destroy_command(decorators=lookup_options))
publication.add_command(role_command(decorators=lookup_options))
2 changes: 2 additions & 0 deletions pulpcore/cli/gem/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
pulp_group,
remote_filter_options,
remote_lookup_option,
role_command,
show_command,
update_command,
)
Expand Down Expand Up @@ -70,3 +71,4 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, remote_type: str) -> No
)
remote.add_command(destroy_command(decorators=lookup_options))
remote.add_command(label_command(decorators=nested_lookup_options))
remote.add_command(role_command(decorators=nested_lookup_options))
2 changes: 2 additions & 0 deletions pulpcore/cli/gem/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
repository_lookup_option,
resource_option,
retained_versions_option,
role_command,
show_command,
update_command,
version_command,
Expand Down Expand Up @@ -109,6 +110,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, repo_type: str) ->
repository.add_command(task_command(decorators=nested_lookup_options))
repository.add_command(version_command(decorators=nested_lookup_options))
repository.add_command(label_command(decorators=nested_lookup_options))
repository.add_command(role_command(decorators=nested_lookup_options))
repository.add_command(
repository_content_command(
contexts={"gem": PulpGemContentContext},
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
packages=plugin_packages,
package_data={package: ["py.typed"] for package in plugin_packages},
python_requires=">=3.6",
install_requires=["pulp-cli>=0.19.0", "pulp-glue-gem==0.2.0.dev"],
install_requires=["pulp-cli>=0.20.0", "pulp-glue-gem==0.2.0.dev"],
entry_points={
"pulp_cli.plugins": [f"{name}={module}" for name, module in plugin_entry_points],
},
Expand Down
20 changes: 14 additions & 6 deletions tests/scripts/pulp_gem/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ REMOTE2_HREF="$(pulp gem remote create --name "cli_test_gem_remote2" --url "http
expect_succ pulp gem repository list

expect_succ pulp gem repository create --name "cli_test_gem_repo" --description "Test repository for CLI tests"
## Use this version only after switching to pulp-cli >= 0.20
# if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
if pulp debug has-plugin --name "gem" --min-version "0.1.0"
if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
then
expect_succ pulp gem repository update --repository "cli_test_gem_repo" --description "" --remote "cli_test_gem_remote1"
else
expect_succ pulp gem repository update --repository "cli_test_gem_repo" --description ""
fi
expect_succ pulp gem repository show --repository "cli_test_gem_repo"
## Use this version only after switching to pulp-cli >= 0.20
# if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
if pulp debug has-plugin --name "gem" --min-version "0.1.0"
if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
then
expect_succ test "$(echo "$OUTPUT" | jq -r '.remote')" = "$REMOTE1_HREF"
expect_succ pulp gem repository update --repository "cli_test_gem_repo" --remote "$REMOTE2_HREF"
Expand All @@ -43,4 +39,16 @@ expect_succ test "$(echo "$OUTPUT" | jq -r '.description')" = ""
expect_succ pulp gem repository list
test "$(echo "$OUTPUT" | jq -r '.|length')" != "0"

if pulp debug has-plugin --name "gem" --specifier ">=0.4.0.dev"
then
# Remove this condition, once the feature is merged.
if [ "$(pulp debug openapi operation-ids | jq -r '[.[]|select(startswith("repositories_gem_gem_my_permission"))]|length')" = 1 ]
then
expect_succ pulp gem repository role my-permissions --repository "cli_test_gem_repo"
expect_succ pulp gem repository role list --repository "cli_test_gem_repo"
expect_succ pulp gem repository role add --role gem.gemrepository_viewer --user admin --repository "cli_test_gem_repo"
expect_succ pulp gem repository role remove --role gem.gemrepository_viewer --user admin --repository "cli_test_gem_repo"
fi
fi

expect_succ pulp gem repository destroy --name "cli_test_gem_repo"
8 changes: 2 additions & 6 deletions tests/scripts/pulp_gem/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ expect_fail pulp gem repository sync --repository "cli_test_gem_repository"
# Test with remote
expect_succ pulp gem repository sync --repository "cli_test_gem_repository" --remote "cli_test_gem_remote"

## Use this version only after switching to pulp-cli >= 0.20
# if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
if pulp debug has-plugin --name "gem" --min-version "0.1.0"
if pulp debug has-plugin --name "gem" --specifier ">=0.1.0"
then
# Preconfigure remote
expect_succ pulp gem repository update --repository "cli_test_gem_repository" --remote "cli_test_gem_remote"
Expand All @@ -38,9 +36,7 @@ expect_succ pulp gem repository version list --repository "cli_test_gem_reposito
expect_succ test "$(echo "$OUTPUT" | jq -r length)" -eq 2
expect_succ pulp gem repository version show --repository "cli_test_gem_repository" --version 1

## Use this version only after switching to pulp-cli >= 0.20
# if pulp debug has-plugin --name "gem" --specifier ">=0.1.1"
if pulp debug has-plugin --name "gem" --min-version "0.1.1"
if pulp debug has-plugin --name "gem" --specifier ">=0.1.1"
then
expect_succ test "$(echo "$OUTPUT" | jq -r '.content_summary.present."gem.gem".count')" -eq 4
fi
Expand Down

0 comments on commit 055f101

Please sign in to comment.