Skip to content

Commit

Permalink
move the diracx_min_client_version string into a dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
natthan-pigoux committed Sep 16, 2024
1 parent 38b4c88 commit 672df6a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
2 changes: 1 addition & 1 deletion diracx-routers/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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"]
Expand Down
14 changes: 1 addition & 13 deletions diracx-routers/src/diracx/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,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.",
Expand All @@ -491,10 +483,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")
Expand Down
1 change: 1 addition & 0 deletions diracx-routers/src/diracx/routers/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIRACX_MIN_CLIENT_VERSION = "0.0.1"

0 comments on commit 672df6a

Please sign in to comment.