From 47c8a1e6fa9931c6705b272d9d71e58190497c57 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Mon, 6 Mar 2023 13:48:32 +0100 Subject: [PATCH] WIP Add global repository version list command fixes #631 --- pulp-glue/pulp_glue/common/context.py | 32 ++++++++++++++++++++++++-- pulpcore/cli/common/generic.py | 33 +++++++++++++++------------ pulpcore/cli/core/repository.py | 2 ++ 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/pulp-glue/pulp_glue/common/context.py b/pulp-glue/pulp_glue/common/context.py index d32b36fc4..296314f9b 100644 --- a/pulp-glue/pulp_glue/common/context.py +++ b/pulp-glue/pulp_glue/common/context.py @@ -137,6 +137,26 @@ def _patch_api_spec(self) -> None: and parameter["schema"]["type"] == "string" ): parameter["schema"] = {"type": "array", "items": {"type": "string"}} + if self.has_plugin(PluginRequirement("core", max="99.99.0")): + # https://github.com/pulp/pulpcore/issues/3634 + for operation_id, (method, path) in self.api.operations.items(): + if ( + operation_id == "repository_versions_list" + or ( + operation_id.startswith("repositories_") + and operation_id.endswith("_versions_list") + ) + or (operation_id.startswith("publications_") and operation_id.endswith("_list")) + ): + operation = api_spec["paths"][path][method] + for parameter in operation["parameters"]: + if ( + parameter["name"] == "content__in" + and parameter["in"] == "query" + and "schema" in parameter + and parameter["schema"]["type"] == "string" + ): + parameter["schema"] = {"type": "array", "items": {"type": "string"}} if self.has_plugin(PluginRequirement("file", max="1.11.0")): operation = api_spec["paths"]["{file_file_alternate_content_source_href}refresh/"][ "post" @@ -465,6 +485,10 @@ def pulp_href(self, value: str) -> None: self._entity_lookup = {"pulp_href": value} self._entity = None + @property + def tangible(self) -> bool: + return bool(self._entity) or bool(self._entity_lookup) + def __init__( self, pulp_ctx: PulpContext, @@ -734,6 +758,7 @@ class PulpRepositoryVersionContext(PulpEntityContext): ENTITY = _("repository version") ENTITIES = _("repository versions") + ID_PREFIX = "repository_versions" repository_ctx: "PulpRepositoryContext" def __init__(self, pulp_ctx: PulpContext, repository_ctx: "PulpRepositoryContext") -> None: @@ -742,7 +767,10 @@ def __init__(self, pulp_ctx: PulpContext, repository_ctx: "PulpRepositoryContext @property def scope(self) -> Dict[str, Any]: - return {self.repository_ctx.HREF: self.repository_ctx.pulp_href} + if self.repository_ctx.tangible: + return {self.repository_ctx.HREF: self.repository_ctx.pulp_href} + else: + return {} def repair(self, href: Optional[str] = None) -> Any: return self.call("repair", parameters={self.HREF: href or self.pulp_href}, body={}) @@ -759,7 +787,7 @@ class PulpRepositoryContext(PulpEntityContext): ENTITIES = _("repositories") HREF_PATTERN = r"repositories/(?P[\w\-_]+)/(?P[\w\-_]+)/" ID_PREFIX = "repositories" - VERSION_CONTEXT: ClassVar[Type[PulpRepositoryVersionContext]] + VERSION_CONTEXT: ClassVar[Type[PulpRepositoryVersionContext]] = PulpRepositoryVersionContext NULLABLES = {"description", "retain_repo_versions"} def get_version_context(self) -> PulpRepositoryVersionContext: diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index dcb48b120..f17734cab 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -1143,6 +1143,7 @@ def version_command(**kwargs: Any) -> click.Command: kwargs.setdefault("name", "version") decorators = kwargs.pop("decorators", [repository_href_option, repository_option]) + list_only = kwargs.pop("list_only", False) @pulp_group(**kwargs) @pass_repository_context @@ -1153,21 +1154,23 @@ def callback( ) -> None: ctx.obj = repository_ctx.get_version_context() - callback.add_command(list_command(decorators=decorators)) - callback.add_command(show_command(decorators=decorators + [version_option])) - callback.add_command(destroy_command(decorators=decorators + [version_option])) - - @callback.command() - @repository_option - @version_option - @pass_repository_version_context - @pass_pulp_context - def repair( - pulp_ctx: PulpCLIContext, - repository_version_ctx: PulpRepositoryVersionContext, - ) -> None: - result = repository_version_ctx.repair() - pulp_ctx.output_result(result) + callback.add_command(list_command(decorators=decorators + [content_in_option])) + + if not list_only: + callback.add_command(show_command(decorators=decorators + [version_option])) + callback.add_command(destroy_command(decorators=decorators + [version_option])) + + @callback.command() + @repository_option + @version_option + @pass_repository_version_context + @pass_pulp_context + def repair( + pulp_ctx: PulpCLIContext, + repository_version_ctx: PulpRepositoryVersionContext, + ) -> None: + result = repository_version_ctx.repair() + pulp_ctx.output_result(result) return callback diff --git a/pulpcore/cli/core/repository.py b/pulpcore/cli/core/repository.py index 980b5f8c1..148ac8685 100644 --- a/pulpcore/cli/core/repository.py +++ b/pulpcore/cli/core/repository.py @@ -8,6 +8,7 @@ name_filter_options, pass_pulp_context, pulp_group, + version_command, ) translation = get_translation(__name__) @@ -30,3 +31,4 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext) -> None: filter_options = name_filter_options repository.add_command(list_command(decorators=filter_options)) +repository.add_command(version_command(decorators=[], list_only=True))