Skip to content

Commit 04e9a11

Browse files
fix: validator
1 parent 28fdffb commit 04e9a11

File tree

1 file changed

+10
-19
lines changed
  • services/web/server/src/simcore_service_webserver/storage

1 file changed

+10
-19
lines changed

services/web/server/src/simcore_service_webserver/storage/_rest.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
BaseModel,
3838
ByteSize,
3939
TypeAdapter,
40-
field_validator,
4140
)
4241
from servicelib.aiohttp import status
4342
from servicelib.aiohttp.client_session import get_client_session
@@ -488,6 +487,15 @@ class _PathParams(BaseModel):
488487
return create_data_response(payload, status=resp_status)
489488

490489

490+
def _allow_only_simcore(v: int) -> int:
491+
if v != 0:
492+
msg = (
493+
f"Only simcore (location_id='0'), provided location_id='{v}' is not allowed"
494+
)
495+
raise ValueError(msg)
496+
return v
497+
498+
491499
@routes.post(
492500
_storage_locations_prefix + "/{location_id}/export-data", name="export_data"
493501
)
@@ -496,15 +504,7 @@ class _PathParams(BaseModel):
496504
@handle_exceptions
497505
async def export_data(request: web.Request) -> web.Response:
498506
class _PathParams(BaseModel):
499-
location_id: LocationID
500-
501-
@field_validator("location_id")
502-
@classmethod
503-
def allow_only_simcore(cls, v: int) -> int:
504-
if v != 0:
505-
msg = f"Only simcore (location_id='0'), provided location_id='{v}' is not allowed"
506-
raise ValueError(msg)
507-
return v
507+
location_id: Annotated[LocationID, AfterValidator(_allow_only_simcore)]
508508

509509
rabbitmq_rpc_client = get_rabbitmq_rpc_client(request.app)
510510
_req_ctx = AuthenticatedRequestContext.model_validate(request)
@@ -533,15 +533,6 @@ def allow_only_simcore(cls, v: int) -> int:
533533
)
534534

535535

536-
def _allow_only_simcore(v: int) -> int:
537-
if v != 0:
538-
msg = (
539-
f"Only simcore (location_id='0'), provided location_id='{v}' is not allowed"
540-
)
541-
raise ValueError(msg)
542-
return v
543-
544-
545536
@routes.post(_storage_locations_prefix + "/{location_id}/search", name="search")
546537
@login_required
547538
@permission_required("storage.files.*")

0 commit comments

Comments
 (0)