Skip to content

Commit

Permalink
Added backend compat local facts routes (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
danyi1212 authored Jun 23, 2024
1 parent cf9c707 commit 2dd8c45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions horizon/facts/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import Depends, Request, HTTPException
from opal_client import OpalClient
from loguru import logger

from horizon.config import sidecar_config
from horizon.facts.update_subscriber import DataUpdateSubscriber
Expand Down Expand Up @@ -35,9 +36,14 @@ def get_wait_timeout(request: Request) -> float | None:
wait_timeout = request.headers.get(
"X-Wait-timeout", sidecar_config.LOCAL_FACTS_WAIT_TIMEOUT
)
if not wait_timeout:
return None
try:
wait_timeout = float(wait_timeout)
except ValueError as e:
logger.error(
f"Invalid X-Wait-timeout header, expected float, got {wait_timeout!r}"
)
raise HTTPException(
status_code=400,
detail=f"Invalid X-Wait-timeout header, expected float, got {wait_timeout!r}",
Expand Down
1 change: 1 addition & 0 deletions horizon/facts/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ async def forward_request_then_wait_for_update(
@facts_router.api_route(
"/{full_path:path}",
methods=["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
include_in_schema=False,
)
async def forward_remaining_requests(
request: FastApiRequest, client: FactsClientDependency, full_path: str
Expand Down
7 changes: 7 additions & 0 deletions horizon/pdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ def _configure_api_routes(self, app: FastAPI):
tags=["Local Facts API"],
dependencies=[Depends(enforce_pdp_token)],
)
app.include_router(
facts_router,
prefix="/v2/facts/{proj_id}/{env_id}",
tags=["Local Facts API (compat)"],
include_in_schema=False,
dependencies=[Depends(enforce_pdp_token)],
)

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

0 comments on commit 2dd8c45

Please sign in to comment.