From 74509627ce60661f76cfbc6f5ff387c66a8ba148 Mon Sep 17 00:00:00 2001 From: natthan-pigoux Date: Mon, 16 Sep 2024 16:13:44 +0200 Subject: [PATCH] move the diracx_min_client_version string into a dedicated file --- diracx-routers/pyproject.toml | 2 +- diracx-routers/src/diracx/routers/__init__.py | 14 +------------- diracx-routers/src/diracx/routers/version.py | 1 + 3 files changed, 3 insertions(+), 14 deletions(-) create mode 100644 diracx-routers/src/diracx/routers/version.py diff --git a/diracx-routers/pyproject.toml b/diracx-routers/pyproject.toml index 886218fbb..7471e86ee 100644 --- a/diracx-routers/pyproject.toml +++ b/diracx-routers/pyproject.toml @@ -57,7 +57,7 @@ WMSAccessPolicy = "diracx.routers.job_manager.access_policies:WMSAccessPolicy" SandboxAccessPolicy = "diracx.routers.job_manager.access_policies:SandboxAccessPolicy" [project.entry-points."diracx.min_client_version"] -diracx = "diracx.routers:DIRACX_MIN_CLIENT_VERSION" +diracx = "diracx.routers.version:DIRACX_MIN_CLIENT_VERSION" [tool.setuptools.packages.find] where = ["src"] diff --git a/diracx-routers/src/diracx/routers/__init__.py b/diracx-routers/src/diracx/routers/__init__.py index 23f50ac9f..4cf936739 100644 --- a/diracx-routers/src/diracx/routers/__init__.py +++ b/diracx-routers/src/diracx/routers/__init__.py @@ -456,15 +456,7 @@ def __init__(self, app: FastAPI): async def dispatch(self, request: Request, call_next) -> Response: client_version = request.headers.get("DiracX-Client-Version") - if not client_version: - logger.info("DiracX-Client-Version header is missing.") - # TODO: if the request comes from web or swagger (other?), - # the header will be missing > how to manage that? - # raise HTTPException( - # status_code=HTTPStatus.BAD_REQUEST, - # detail="Client version header is missing.", - # ) - elif self.is_version_too_old(client_version): + if client_version and self.is_version_too_old(client_version): raise HTTPException( status_code=HTTPStatus.UPGRADE_REQUIRED, detail=f"Client version ({client_version}) not recent enough (>= {self.min_client_version}). Upgrade.", @@ -482,10 +474,6 @@ def is_version_too_old(self, client_version: str) -> bool | None: return None -# I'm not sure if this has to be define here: -DIRACX_MIN_CLIENT_VERSION = "0.0.1" - - def get_min_client_version(): """Extracting min client version from entry_points and seraching for extension.""" matched_entry_points: EntryPoints = entry_points(group="diracx.min_client_version") diff --git a/diracx-routers/src/diracx/routers/version.py b/diracx-routers/src/diracx/routers/version.py new file mode 100644 index 000000000..7c57daf03 --- /dev/null +++ b/diracx-routers/src/diracx/routers/version.py @@ -0,0 +1 @@ +DIRACX_MIN_CLIENT_VERSION = "0.0.1"