Skip to content

Commit

Permalink
Validate RPM copy
Browse files Browse the repository at this point in the history
The specification of the various copy apis collide both on the
operationId as well as on the request body schema. This adds an api
quirk to fix it for rpm (the one we have currently implemented).

(cherry picked from commit 7c47eeb)
  • Loading branch information
mdellweg committed Jul 31, 2024
1 parent 0dec067 commit 64aa0d6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/pulp-glue/+fix_rpm_copy_spec.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the api spec of the RPM copy command so it does not collide with other copy implementations.
37 changes: 33 additions & 4 deletions pulp-glue/pulp_glue/rpm/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,43 @@
PulpRepositoryContext,
PulpRepositoryVersionContext,
PulpViewSetContext,
api_quirk,
)
from pulp_glue.common.i18n import get_translation
from pulp_glue.common.openapi import OpenAPI

translation = get_translation(__package__)
_ = translation.gettext


@api_quirk(PluginRequirement("rpm", specifier=">=3.3.0"))
def patch_rpm_copy_scheme(api: OpenAPI) -> None:
path, operation = next(
(
(k, v["post"])
for k, v in api.api_spec["paths"].items()
if k.endswith("/api/v3/rpm/copy/")
)
)
api.api_spec["components"]["schemas"]["RpmCopy"] = {
"type": "object",
"description": "A serializer for Content Copy API.",
"properties": {
"config": {
"description": "A JSON document describing sources, destinations,"
" and content to be copied"
},
"dependency_solving": {"type": "boolean"},
},
"required": ["config"],
}
operation["operationId"] = "rpm_copy_content"
for item in operation["requestBody"]["content"].values():
item["schema"]["$ref"] = "#/components/schemas/RpmCopy"

api.operations["rpm_copy_content"] = ("post", path)


class PulpRpmACSContext(PulpACSContext):
PLUGIN = "rpm"
RESOURCE_TYPE = "rpm"
Expand Down Expand Up @@ -378,7 +408,8 @@ def prune_packages(


class PulpRpmCopyContext(PulpViewSetContext):
COPY_ID: t.ClassVar[str] = "copy_content"
COPY_ID: t.ClassVar[str] = "rpm_copy_content"
NEEDS_PLUGINS = [PluginRequirement("rpm", specifier=">=3.3.0")]

def copy(
self,
Expand All @@ -389,6 +420,4 @@ def copy(
"config": config,
"dependency_solving": dependency_solving,
}
# Validation fails because config is not a dict(), and
# drf-spectacular thinks all type:object refs must be dict
return self.call("copy", body=body, validate_body=False)
return self.call("copy", body=body)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools"]
requires = ["setuptools<73"]
build-backend = "setuptools.build_meta"

[project]
Expand Down

0 comments on commit 64aa0d6

Please sign in to comment.