Skip to content

Commit

Permalink
validate input not null and sanitize key
Browse files Browse the repository at this point in the history
  • Loading branch information
p3t3r67x0 committed Dec 25, 2024
1 parent 58d445e commit ad4b60a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/schemathesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
steps:
- uses: schemathesis/action@v1
with:
schema: https://api.oklabflensburg.de/openapi.json --experimental=openapi-3.1
schema: 'https://api.oklabflensburg.de/openapi.json --experimental=openapi-3.1'
11 changes: 10 additions & 1 deletion app/services/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from sqlalchemy.orm import aliased
from fastapi import HTTPException

from ..utils.validators import validate_not_none
from ..utils.sanitizer import sanitize_string
from ..models.climate import DwdStationReference, WeatherStation
from ..models.administrative import Vg250Gem



async def get_dwd_stations_by_municipality_key(session: AsyncSession, municipality_key: str):
try:
validated_key = validate_not_none(municipality_key)
validated_key = sanitize_string(validated_key)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))

geojson = cast(func.ST_AsGeoJSON(DwdStationReference.wkb_geometry, 15), JSON).label('geojson')
gem_alias = aliased(Vg250Gem)

Expand Down Expand Up @@ -41,7 +50,7 @@ async def get_dwd_stations_by_municipality_key(session: AsyncSession, municipali
)
)

result = await session.execute(stmt, {'municipality_key': municipality_key})
result = await session.execute(stmt, {'municipality_key': validated_key})
return result.mappings().all()


Expand Down

0 comments on commit ad4b60a

Please sign in to comment.