From af69adc7258da50520d97a5ea02ac105c8040f5b Mon Sep 17 00:00:00 2001 From: Amund Isaksen Date: Mon, 29 Jan 2024 12:00:22 +0100 Subject: [PATCH] Add parsing of parameter-name --- api/dependencies.py | 10 ++++++++-- api/requirements.in | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/dependencies.py b/api/dependencies.py index 22ba8c0c..286941cc 100644 --- a/api/dependencies.py +++ b/api/dependencies.py @@ -1,6 +1,6 @@ import requests import json - +import isodate from datetime import datetime from datetime import timedelta @@ -71,9 +71,15 @@ def parse_parameter_name(parameter_name): except ValueError: errors.append(f"Level could not be converted to float") - if func not in (legal_func := ["max", "min", "average", "instantaneous", "mean"]): errors.append(f"Unknown function given, {func}, has to be one of {legal_func}") + try: + isodate.parse_duration(period) + except isodate.ISO8601Error: + errors.append(f"Invalid ISO8601 duration") + if not errors: raise HTTPException(400, detail="\n".join(errors)) + + return standard_name, level, func, period diff --git a/api/requirements.in b/api/requirements.in index 2c3ecea2..b6e3680d 100644 --- a/api/requirements.in +++ b/api/requirements.in @@ -12,3 +12,4 @@ covjson-pydantic~=0.2.0 edr-pydantic~=0.2.0 shapely~=2.0 geojson-pydantic~=1.0 +isodate=~0.6