File tree Expand file tree Collapse file tree 4 files changed +26
-8
lines changed
models-library/src/models_library/api_schemas_webserver
service-library/src/servicelib/rabbitmq/rpc_interfaces/storage
storage/src/simcore_service_storage/api/_worker_tasks
web/server/tests/unit/with_dbs/01/storage Expand file tree Collapse file tree 4 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 11from pathlib import Path
2- from typing import Annotated
2+ from typing import Annotated , Any
33
4- from pydantic import BaseModel , Field
4+ from pydantic import BaseModel , BeforeValidator , Field
55
66from ..api_schemas_storage .storage_schemas import (
77 DEFAULT_NUMBER_OF_PATHS_PER_PAGE ,
@@ -37,5 +37,18 @@ class BatchDeletePathsBodyParams(InputSchema):
3737 paths : set [Path ]
3838
3939
40+ def _ensure_valid_path (value : Any ) -> str :
41+ try :
42+ Path (value )
43+ except Exception as e :
44+ msg = f"Provided { value = } is nto a valid path"
45+ raise ValueError (msg ) from e
46+
47+ return value
48+
49+
50+ PathToExport = Annotated [str , BeforeValidator (_ensure_valid_path )]
51+
52+
4053class DataExportPost (InputSchema ):
41- paths : list [Path ]
54+ paths : list [PathToExport ]
Original file line number Diff line number Diff line change 1- from pathlib import Path
2-
31from models_library .api_schemas_rpc_async_jobs .async_jobs import (
42 AsyncJobGet ,
53 AsyncJobNameData ,
64)
75from models_library .api_schemas_storage import STORAGE_RPC_NAMESPACE
86from models_library .api_schemas_storage .storage_schemas import FoldersBody
7+ from models_library .api_schemas_webserver .storage import PathToExport
98from models_library .products import ProductName
109from models_library .rabbitmq_basic_types import RPCMethodName
1110from models_library .users import UserID
@@ -38,7 +37,7 @@ async def start_data_export(
3837 * ,
3938 user_id : UserID ,
4039 product_name : ProductName ,
41- paths_to_export : list [Path ],
40+ paths_to_export : list [PathToExport ],
4241) -> tuple [AsyncJobGet , AsyncJobNameData ]:
4342 job_id_data = AsyncJobNameData (user_id = user_id , product_name = product_name )
4443 async_job_rpc_get = await submit (
Original file line number Diff line number Diff line change 99from models_library .progress_bar import ProgressReport
1010from models_library .projects_nodes_io import StorageFileID
1111from models_library .users import UserID
12+ from pydantic import TypeAdapter
1213from servicelib .logging_utils import log_context
1314from servicelib .progress_bar import ProgressBarData
1415from simcore_service_storage .exceptions .errors import FileAccessRightError
@@ -78,6 +79,11 @@ async def export_data(
7879 )
7980 assert isinstance (dsm , SimcoreS3DataManager ) # nosec
8081
82+ paths_to_export = [
83+ TypeAdapter (StorageFileID ).validate_python (path_to_export )
84+ for path_to_export in paths_to_export
85+ ]
86+
8187 try :
8288 for path_to_export in paths_to_export :
8389 await dsm .can_read_file (user_id = user_id , file_id = path_to_export )
Original file line number Diff line number Diff line change @@ -464,7 +464,7 @@ async def test_data_export(
464464 )
465465
466466 _body = DataExportPost (
467- paths = [Path ( f"{ faker .uuid4 ()} /{ faker .uuid4 ()} /{ faker .file_name ()} " ) ]
467+ paths = [f"{ faker .uuid4 ()} /{ faker .uuid4 ()} /{ faker .file_name ()} " ]
468468 )
469469 response = await client .post (
470470 f"/{ API_VERSION } /storage/locations/0/data-export" , data = _body .model_dump_json ()
@@ -671,7 +671,7 @@ async def test_get_async_job_links(
671671 )
672672
673673 _body = DataExportPost (
674- paths = [Path ( f"{ faker .uuid4 ()} /{ faker .uuid4 ()} /{ faker .file_name ()} " ) ]
674+ paths = [f"{ faker .uuid4 ()} /{ faker .uuid4 ()} /{ faker .file_name ()} " ]
675675 )
676676 response = await client .post (
677677 f"/{ API_VERSION } /storage/locations/0/data-export" , data = _body .model_dump_json ()
You can’t perform that action at this time.
0 commit comments