Skip to content

Commit 2dd8c45

Browse files
authored
Added backend compat local facts routes (#155)
1 parent cf9c707 commit 2dd8c45

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

horizon/facts/dependencies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from fastapi import Depends, Request, HTTPException
44
from opal_client import OpalClient
5+
from loguru import logger
56

67
from horizon.config import sidecar_config
78
from horizon.facts.update_subscriber import DataUpdateSubscriber
@@ -35,9 +36,14 @@ def get_wait_timeout(request: Request) -> float | None:
3536
wait_timeout = request.headers.get(
3637
"X-Wait-timeout", sidecar_config.LOCAL_FACTS_WAIT_TIMEOUT
3738
)
39+
if not wait_timeout:
40+
return None
3841
try:
3942
wait_timeout = float(wait_timeout)
4043
except ValueError as e:
44+
logger.error(
45+
f"Invalid X-Wait-timeout header, expected float, got {wait_timeout!r}"
46+
)
4147
raise HTTPException(
4248
status_code=400,
4349
detail=f"Invalid X-Wait-timeout header, expected float, got {wait_timeout!r}",

horizon/facts/router.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ async def forward_request_then_wait_for_update(
294294
@facts_router.api_route(
295295
"/{full_path:path}",
296296
methods=["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
297+
include_in_schema=False,
297298
)
298299
async def forward_remaining_requests(
299300
request: FastApiRequest, client: FactsClientDependency, full_path: str

horizon/pdp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ def _configure_api_routes(self, app: FastAPI):
356356
tags=["Local Facts API"],
357357
dependencies=[Depends(enforce_pdp_token)],
358358
)
359+
app.include_router(
360+
facts_router,
361+
prefix="/v2/facts/{proj_id}/{env_id}",
362+
tags=["Local Facts API (compat)"],
363+
include_in_schema=False,
364+
dependencies=[Depends(enforce_pdp_token)],
365+
)
359366

360367
# TODO: remove this when clients update sdk version (legacy routes)
361368
@app.post(

0 commit comments

Comments
 (0)