GET /v1/routing-config — active routing mode/tier config. POST — update overrides.
(request: Request)
| 3510 | return JSONResponse(payload, status_code=400) |
| 3511 | |
| 3512 | async def handle_routing_config(request: Request) -> JSONResponse: |
| 3513 | """GET /v1/routing-config — active routing mode/tier config. POST — update overrides.""" |
| 3514 | nonlocal _routing_config |
| 3515 | if request.method == "GET": |
| 3516 | return JSONResponse(_routing_store.export()) |
| 3517 | |
| 3518 | denied = _admin_auth_failure(request) |
| 3519 | if denied is not None: |
| 3520 | return denied |
| 3521 | body = await request.json() |
| 3522 | action = str(body.get("action", "")).strip().lower() |
| 3523 | try: |
| 3524 | if action == "set-default-mode": |
| 3525 | mode = _parse_mode_value(str(body.get("mode", ""))) |
| 3526 | payload = _routing_store.set_default_mode(mode) |
| 3527 | elif action == "set-tier": |
| 3528 | mode = _parse_mode_value(str(body.get("mode", ""))) |
| 3529 | tier = _parse_tier_value(str(body.get("tier", ""))) |
| 3530 | primary = str(body.get("primary", "")).strip() |
| 3531 | fallback_raw = body.get("fallback", []) |
| 3532 | selection_mode = str(body.get("selection_mode", "")).strip().lower() |
| 3533 | hard_pin = bool(body.get("hard_pin", False)) |
| 3534 | if selection_mode: |
| 3535 | hard_pin = selection_mode in {"hard-pin", "hard_pin", "pinned"} |
| 3536 | if isinstance(fallback_raw, str): |
| 3537 | fallback = [part.strip() for part in fallback_raw.split(",") if part.strip()] |
| 3538 | elif isinstance(fallback_raw, list): |
| 3539 | fallback = [str(item).strip() for item in fallback_raw if str(item).strip()] |
| 3540 | else: |
| 3541 | return JSONResponse({"error": "fallback must be a list or comma-separated string"}, status_code=400) |
| 3542 | payload = _routing_store.set_tier( |
| 3543 | mode, |
| 3544 | tier, |
| 3545 | primary=primary, |
| 3546 | fallback=fallback, |
| 3547 | hard_pin=hard_pin, |
| 3548 | ) |
| 3549 | elif action == "reset-tier": |
| 3550 | mode = _parse_mode_value(str(body.get("mode", ""))) |
| 3551 | tier = _parse_tier_value(str(body.get("tier", ""))) |
| 3552 | payload = _routing_store.reset_tier(mode, tier) |
| 3553 | elif action == "reset-default-mode": |
| 3554 | payload = _routing_store.reset_default_mode() |
| 3555 | elif action == "reset": |
| 3556 | payload = _routing_store.reset() |
| 3557 | else: |
| 3558 | return JSONResponse( |
| 3559 | { |
| 3560 | "error": "Invalid action", |
| 3561 | "allowed": [ |
| 3562 | "set-default-mode", |
| 3563 | "set-tier", |
| 3564 | "reset-tier", |
| 3565 | "reset-default-mode", |
| 3566 | "reset", |
| 3567 | ], |
| 3568 | }, |
| 3569 | status_code=400, |
nothing calls this directly
no test coverage detected