Skip to content

Commit

Permalink
WIP Add global repository version list command
Browse files Browse the repository at this point in the history
fixes pulp#631
  • Loading branch information
mdellweg committed Mar 6, 2023
1 parent 314dc7c commit 47c8a1e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
32 changes: 30 additions & 2 deletions pulp-glue/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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={})
Expand All @@ -759,7 +787,7 @@ class PulpRepositoryContext(PulpEntityContext):
ENTITIES = _("repositories")
HREF_PATTERN = r"repositories/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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:
Expand Down
33 changes: 18 additions & 15 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pulpcore/cli/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
name_filter_options,
pass_pulp_context,
pulp_group,
version_command,
)

translation = get_translation(__name__)
Expand All @@ -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))

0 comments on commit 47c8a1e

Please sign in to comment.