diff --git a/karapace/schema_registry.py b/karapace/schema_registry.py index 311baaa2a..444a5f895 100644 --- a/karapace/schema_registry.py +++ b/karapace/schema_registry.py @@ -475,7 +475,7 @@ def update_require_validation_for_topic( topic_name: TopicName, skip_validation: bool, ) -> None: - key = {"topic": topic_name, "keytype": str(MessageType.schema_validation), "magic": 0} + key = {"keytype": str(MessageType.schema_validation), "magic": 0} value = {"skip_validation": skip_validation, "topic": topic_name} self.producer.send_message(key=key, value=value) diff --git a/karapace/schema_registry_apis.py b/karapace/schema_registry_apis.py index 373cf00a9..0c90ccdfa 100644 --- a/karapace/schema_registry_apis.py +++ b/karapace/schema_registry_apis.py @@ -621,8 +621,13 @@ async def config_set(self, content_type: str, *, request: HTTPRequest, user: Use elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/config" - await self._forward_request_remote(request=request, body=body, url=url, content_type=content_type, method="PUT") + await self._forward_request_remote( + request=request, + body=body, + url=compute_forwarded_url(master_url=master_url, request_url=request.url), + content_type=content_type, + method="PUT", + ) self.r({"compatibility": self.schema_registry.schema_reader.config["compatibility"]}, content_type) @@ -692,9 +697,12 @@ async def config_subject_set( elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/config/{subject}" await self._forward_request_remote( - request=request, body=request.json, url=url, content_type=content_type, method="PUT" + request=request, + body=request.json, + url=compute_forwarded_url(master_url=master_url, request_url=request.url), + content_type=content_type, + method="PUT", ) self.r({"compatibility": compatibility_level.value}, content_type) @@ -717,9 +725,12 @@ async def config_subject_delete( elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/config/{subject}" await self._forward_request_remote( - request=request, body=request.json, url=url, content_type=content_type, method="PUT" + request=request, + body=request.json, + url=compute_forwarded_url(master_url=master_url, request_url=request.url), + content_type=content_type, + method="PUT", ) self.r({"compatibility": self.schema_registry.schema_reader.config["compatibility"]}, content_type) @@ -791,8 +802,13 @@ async def subject_delete( elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/subjects/{subject}?permanent={permanent}" - await self._forward_request_remote(request=request, body={}, url=url, content_type=content_type, method="DELETE") + await self._forward_request_remote( + request=request, + body={}, + url=compute_forwarded_url(master_url=master_url, request_url=request.url + f"?permanent={permanent}"), + content_type=content_type, + method="DELETE", + ) async def subject_version_get( self, content_type: str, *, subject: str, version: str, request: HTTPRequest, user: User | None = None @@ -894,8 +910,13 @@ async def subject_version_delete( elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/subjects/{subject}/versions/{version}?permanent={permanent}" - await self._forward_request_remote(request=request, body={}, url=url, content_type=content_type, method="DELETE") + await self._forward_request_remote( + request=request, + body={}, + url=compute_forwarded_url(master_url=master_url, request_url=request.url + f"?permanent={permanent}"), + content_type=content_type, + method="DELETE", + ) async def subject_version_schema_get( self, content_type: str, *, subject: str, version: str, user: User | None = None @@ -1279,8 +1300,13 @@ async def subject_post( elif not master_url: self.no_master_error(content_type) else: - url = f"{master_url}/subjects/{subject}/versions" - await self._forward_request_remote(request=request, body=body, url=url, content_type=content_type, method="POST") + await self._forward_request_remote( + request=request, + body=body, + url=compute_forwarded_url(master_url=master_url, request_url=request.url), + content_type=content_type, + method="POST", + ) async def is_topic_requiring_validation(self, content_type: str, *, topic: str) -> None: require_validation = self.schema_registry.is_topic_requiring_validation(topic_name=TopicName(topic)) diff --git a/tests/unit/test_schema_registry_api.py b/tests/unit/test_schema_registry_api.py index bc6019951..771e10c62 100644 --- a/tests/unit/test_schema_registry_api.py +++ b/tests/unit/test_schema_registry_api.py @@ -53,12 +53,3 @@ async def test_forward_when_not_ready(): request=ANY, body=None, url="http://primary-url/schemas/ids/1", content_type="application/json", method="GET" ) - -def test_compute_forwarded_url() -> None: - assert ( - compute_forwarded_url( - master_url="http://localhost:8081/another/fancy/path", - request_url="https://docs.python.org/3/library/urllib.parse.html", - ) - == "http://localhost:8081/3/library/urllib.parse.html" - )