|
34 | 34 | from karapace.schema_models import ParsedTypedSchema, SchemaType, SchemaVersion, TypedSchema, ValidatedTypedSchema |
35 | 35 | from karapace.schema_references import LatestVersionReference, Reference, reference_from_mapping |
36 | 36 | from karapace.schema_registry import KarapaceSchemaRegistry, validate_version |
37 | | -from karapace.typing import JsonData, JsonObject, ResolvedVersion, SchemaId |
| 37 | +from karapace.typing import JsonData, JsonObject, ResolvedVersion, SchemaId, Subject |
38 | 38 | from karapace.utils import JSONDecodeError |
39 | 39 | from typing import Any |
40 | 40 |
|
@@ -302,6 +302,24 @@ def _add_schema_registry_routes(self) -> None: |
302 | 302 | json_body=False, |
303 | 303 | auth=self._auth, |
304 | 304 | ) |
| 305 | + self.route( |
| 306 | + "/mode", |
| 307 | + callback=self.get_global_mode, |
| 308 | + method="GET", |
| 309 | + schema_request=True, |
| 310 | + with_request=False, |
| 311 | + json_body=False, |
| 312 | + auth=self._auth, |
| 313 | + ) |
| 314 | + self.route( |
| 315 | + "/mode/<subject:path>", |
| 316 | + callback=self.get_subject_mode, |
| 317 | + method="GET", |
| 318 | + schema_request=True, |
| 319 | + with_request=False, |
| 320 | + json_body=False, |
| 321 | + auth=self._auth, |
| 322 | + ) |
305 | 323 |
|
306 | 324 | async def close(self) -> None: |
307 | 325 | self.log.info("Closing karapace_schema_registry_controller") |
@@ -1245,6 +1263,44 @@ async def subject_post( |
1245 | 1263 | url = f"{master_url}/subjects/{subject}/versions" |
1246 | 1264 | await self._forward_request_remote(request=request, body=body, url=url, content_type=content_type, method="POST") |
1247 | 1265 |
|
| 1266 | + async def get_global_mode( |
| 1267 | + self, |
| 1268 | + content_type: str, |
| 1269 | + *, |
| 1270 | + user: User | None = None, |
| 1271 | + ) -> None: |
| 1272 | + self._check_authorization(user, Operation.Read, "Config:") |
| 1273 | + self.r( |
| 1274 | + body={"mode": str(self.schema_registry.get_global_mode())}, |
| 1275 | + content_type=content_type, |
| 1276 | + status=HTTPStatus.OK, |
| 1277 | + ) |
| 1278 | + |
| 1279 | + async def get_subject_mode( |
| 1280 | + self, |
| 1281 | + content_type: str, |
| 1282 | + *, |
| 1283 | + subject: str, |
| 1284 | + user: User | None = None, |
| 1285 | + ) -> None: |
| 1286 | + self._check_authorization(user, Operation.Read, f"Subject:{subject}") |
| 1287 | + |
| 1288 | + if self.schema_registry.database.find_subject(subject=Subject(subject)) is None: |
| 1289 | + self.r( |
| 1290 | + body={ |
| 1291 | + "error_code": SchemaErrorCodes.SUBJECT_NOT_FOUND.value, |
| 1292 | + "message": SchemaErrorMessages.SUBJECT_NOT_FOUND_FMT.value.format(subject=subject), |
| 1293 | + }, |
| 1294 | + content_type=content_type, |
| 1295 | + status=HTTPStatus.NOT_FOUND, |
| 1296 | + ) |
| 1297 | + |
| 1298 | + self.r( |
| 1299 | + body={"mode": str(self.schema_registry.get_global_mode())}, |
| 1300 | + content_type=content_type, |
| 1301 | + status=HTTPStatus.OK, |
| 1302 | + ) |
| 1303 | + |
1248 | 1304 | def get_schema_id_if_exists(self, *, subject: str, schema: TypedSchema, include_deleted: bool) -> SchemaId | None: |
1249 | 1305 | schema_id = self.schema_registry.database.get_schema_id_if_exists( |
1250 | 1306 | subject=subject, schema=schema, include_deleted=include_deleted |
|
0 commit comments