Skip to content

Commit

Permalink
Prepend root_path to url for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
slesaad committed May 22, 2024
1 parent f2f0c40 commit 795dabf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 0 additions & 2 deletions stac_api/runtime/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

from mangum import Mangum
from src.app import app
from src.config import ApiSettings
from src.monitoring import logger, metrics, tracer

settings = ApiSettings()

logging.getLogger("mangum.lifespan").setLevel(logging.ERROR)
logging.getLogger("mangum.http").setLevel(logging.ERROR)
Expand Down
19 changes: 16 additions & 3 deletions stac_api/runtime/src/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from stac_pydantic import Item, Collection
from starlette.middleware.base import BaseHTTPMiddleware

from src.config import ApiSettings


api_settings = ApiSettings()
prepend_path = api_settings.root_path or ""


class Items(BaseModel):
items: Dict[str, Item]
Expand All @@ -24,13 +30,20 @@ async def dispatch(self, request: Request, call_next):
try:
body = await request.body()
request_data = json.loads(body)
if re.match(r"^/collections(?:/[^/]+)?$", request.url.path):
if re.match(
f"^{prepend_path}/collections(?:/[^/]+)?$",
request.url.path,
):
Collection(**request_data)
elif re.match(
r"^/collections/[^/]+/items(?:/[^/]+)?$", request.url.path
f"^{prepend_path}/collections/[^/]+/items(?:/[^/]+)?$",
request.url.path,
):
Item(**request_data)
elif re.match(r"^/collections/[^/]+/bulk-items$", request.url.path):
elif re.match(
f"^{prepend_path}/collections/[^/]+/bulk-items$",
request.url.path,
):
BulkItemsModel(**request_data)
except (ValidationError, json.JSONDecodeError) as e:
raise HTTPException(status_code=400, detail=str(e))
Expand Down

0 comments on commit 795dabf

Please sign in to comment.