Skip to content
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

Add role commands for file #455

Merged
merged 1 commit into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/454.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added role management commands to file commands.
2 changes: 2 additions & 0 deletions pulpcore/cli/file/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
list_command,
name_option,
resource_option,
role_command,
show_command,
update_command,
)
Expand Down Expand Up @@ -111,6 +112,7 @@ def remove(acs_ctx: PulpFileACSContext, paths: Iterable[str]) -> None:
acs.add_command(create_command(decorators=create_options))
acs.add_command(update_command(decorators=lookup_options + update_options))
acs.add_command(destroy_command(decorators=lookup_options))
acs.add_command(role_command(decorators=lookup_options))


@acs.command()
Expand Down
9 changes: 8 additions & 1 deletion pulpcore/cli/file/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PulpFileACSContext(PulpEntityContext):
ENTITIES = _("file ACSes")
HREF = "file_file_alternate_content_source_href"
ID_PREFIX = "acs_file_file"
CAPABILITIES = {"roles": [PluginRequirement("file", min="1.11.0.dev")]}

def refresh(self, href: str) -> Any:
return self.call("refresh", parameters={self.HREF: href})
Expand All @@ -39,6 +40,7 @@ class PulpFileDistributionContext(PulpEntityContext):
HREF = "file_file_distribution_href"
ID_PREFIX = "distributions_file_file"
NULLABLES = {"publication", "repository"}
CAPABILITIES = {"roles": [PluginRequirement("file", min="1.11.0.dev")]}

def preprocess_body(self, body: EntityDefinition) -> EntityDefinition:
body = super().preprocess_body(body)
Expand All @@ -55,6 +57,7 @@ class PulpFilePublicationContext(PulpEntityContext):
ENTITIES = _("file publications")
HREF = "file_file_publication_href"
ID_PREFIX = "publications_file_file"
CAPABILITIES = {"roles": [PluginRequirement("file", min="1.11.0.dev")]}

def preprocess_body(self, body: EntityDefinition) -> EntityDefinition:
body = super().preprocess_body(body)
Expand All @@ -70,6 +73,7 @@ class PulpFileRemoteContext(PulpRemoteContext):
ENTITIES = _("file remotes")
HREF = "file_file_remote_href"
ID_PREFIX = "remotes_file_file"
CAPABILITIES = {"roles": [PluginRequirement("file", min="1.11.0.dev")]}


class PulpFileRepositoryVersionContext(PulpRepositoryVersionContext):
Expand All @@ -81,7 +85,10 @@ class PulpFileRepositoryContext(PulpRepositoryContext):
HREF = "file_file_repository_href"
ID_PREFIX = "repositories_file_file"
VERSION_CONTEXT = PulpFileRepositoryVersionContext
CAPABILITIES = {"pulpexport": [PluginRequirement("file")]}
CAPABILITIES = {
"pulpexport": [PluginRequirement("file")],
"roles": [PluginRequirement("file", min="1.11.0.dev")],
}


registered_repository_contexts["file:file"] = PulpFileRepositoryContext
2 changes: 2 additions & 0 deletions pulpcore/cli/file/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
list_command,
name_option,
resource_option,
role_command,
show_command,
update_command,
)
Expand Down Expand Up @@ -73,3 +74,4 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s
distribution.add_command(update_command(decorators=lookup_options + update_options))
distribution.add_command(destroy_command(decorators=lookup_options))
distribution.add_command(label_command())
distribution.add_command(role_command(decorators=lookup_options))
2 changes: 2 additions & 0 deletions pulpcore/cli/file/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
list_command,
publication_filter_options,
resource_option,
role_command,
show_command,
)
from pulpcore.cli.common.i18n import get_translation
Expand Down Expand Up @@ -57,3 +58,4 @@ def publication(ctx: click.Context, pulp_ctx: PulpContext, publication_type: str
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/file/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
label_select_option,
list_command,
name_option,
role_command,
show_command,
update_command,
)
Expand Down Expand Up @@ -53,3 +54,4 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None:
)
remote.add_command(destroy_command(decorators=lookup_options))
remote.add_command(label_command())
remote.add_command(role_command(decorators=lookup_options))
2 changes: 2 additions & 0 deletions pulpcore/cli/file/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
repository_option,
resource_option,
retained_versions_option,
role_command,
show_command,
update_command,
version_command,
Expand Down Expand Up @@ -164,6 +165,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non
modify_decorators=modify_options,
)
)
repository.add_command(role_command(decorators=lookup_options))


@repository.command()
Expand Down
35 changes: 35 additions & 0 deletions tests/scripts/pulp_file/test_role.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "file" --min-version "1.11.0.dev" || exit 3

USERPASS="Yeech6ba"

cleanup() {
pulp user destroy --username "clitest" || true
pulp file repository destroy --name "clitest" || true
}
trap cleanup EXIT

pulp user create --username "clitest" --password "${USERPASS}"

expect_succ pulp --username clitest --password "${USERPASS}" file repository list
test "$(echo "${OUTPUT}" | jq -r 'length' )" = "0"

expect_deny pulp --username clitest --password "${USERPASS}" file repository create --name "clitest"
expect_succ pulp file repository create --name "clitest"
REPOSITORY_HREF=$(jq -r '.pulp_href' <<<"${OUTPUT}")
expect_fail pulp --username clitest --password "${USERPASS}" file repository show --name "clitest"
expect_fail pulp --username clitest --password "${USERPASS}" file repository show --href "${REPOSITORY_HREF}"

expect_succ pulp file repository role add --name "clitest" --user "clitest" --role "file.filerepository_viewer"
expect_succ pulp --username clitest --password "${USERPASS}" file repository show --name "clitest"
expect_succ pulp --username clitest --password "${USERPASS}" file repository show --href "${REPOSITORY_HREF}"

expect_deny pulp --username clitest --password "${USERPASS}" file repository update --href "${REPOSITORY_HREF}" --retain-repo-versions 1

expect_succ pulp file repository role remove --name "clitest" --user "clitest" --role "file.filerepository_viewer"
expect_fail pulp --username clitest --password "${USERPASS}" file repository show --name "clitest"
expect_fail pulp --username clitest --password "${USERPASS}" file repository show --href "${REPOSITORY_HREF}"