Skip to content

Commit 8dd2b47

Browse files
feat: add web server rest
1 parent ba8cf52 commit 8dd2b47

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

api/specs/web-server/_storage.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ListPathsQueryParams,
2828
StorageLocationPathParams,
2929
StoragePathComputeSizeParams,
30+
SearchBodyParams
3031
)
3132
from models_library.generics import Envelope
3233
from models_library.projects_nodes_io import LocationID
@@ -236,3 +237,16 @@ async def is_completed_upload_file(
236237
)
237238
async def export_data(export_data: DataExportPost, location_id: LocationID):
238239
"""Trigger data export. Returns async job id for getting status and results"""
240+
241+
242+
@router.post(
243+
"/storage/locations/{location_id}/search",
244+
response_model=Envelope[TaskGet],
245+
name="search",
246+
description="Starts a files/folders search",
247+
)
248+
async def search(
249+
_path: Annotated[StorageLocationPathParams, Depends()],
250+
_body: SearchBodyParams,
251+
):
252+
"""Trigger search. Returns async job id for getting status and results"""

packages/models-library/src/models_library/api_schemas_webserver/storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ class BatchDeletePathsBodyParams(InputSchema):
4242

4343
class DataExportPost(InputSchema):
4444
paths: list[PathToExport]
45+
46+
47+
class SearchBodyParams(InputSchema):
48+
name_pattern: str

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7568,6 +7568,33 @@ paths:
75687568
schema:
75697569
$ref: '#/components/schemas/EnvelopedError'
75707570
description: Internal Server Error
7571+
/v0/storage/locations/{location_id}/search:
7572+
post:
7573+
tags:
7574+
- storage
7575+
summary: Search
7576+
description: Search
7577+
operationId: search
7578+
parameters:
7579+
- name: location_id
7580+
in: path
7581+
required: true
7582+
schema:
7583+
type: integer
7584+
title: Location Id
7585+
requestBody:
7586+
required: true
7587+
content:
7588+
application/json:
7589+
schema:
7590+
$ref: '#/components/schemas/SearchBodyParams'
7591+
responses:
7592+
'200':
7593+
description: Successful Response
7594+
content:
7595+
application/json:
7596+
schema:
7597+
$ref: '#/components/schemas/Envelope_TaskGet_'
75717598
/v0/trash:empty:
75727599
post:
75737600
tags:
@@ -16423,6 +16450,15 @@ components:
1642316450
\ - A worker has picked up the task and is executing it\n- SUCCESS - Task\
1642416451
\ finished successfully\n- FAILED - Task finished with an error\n- ABORTED\
1642516452
\ - Task was aborted before completion"
16453+
SearchBodyParams:
16454+
properties:
16455+
namePattern:
16456+
type: string
16457+
title: Namepattern
16458+
type: object
16459+
required:
16460+
- namePattern
16461+
title: SearchBodyParams
1642616462
SelectBox:
1642716463
properties:
1642816464
structure:

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from models_library.api_schemas_webserver.storage import (
2323
BatchDeletePathsBodyParams,
2424
DataExportPost,
25+
SearchBodyParams,
2526
StorageLocationPathParams,
2627
StoragePathComputeSizeParams,
2728
)
@@ -44,7 +45,7 @@
4445
from servicelib.rabbitmq.rpc_interfaces.storage.paths import (
4546
delete_paths as remote_delete_paths,
4647
)
47-
from servicelib.rabbitmq.rpc_interfaces.storage.simcore_s3 import start_export_data
48+
from servicelib.rabbitmq.rpc_interfaces.storage.simcore_s3 import start_export_data, start_search
4849
from servicelib.request_keys import RQT_USERID_KEY
4950
from servicelib.rest_responses import unwrap_envelope
5051
from yarl import URL
@@ -509,3 +510,45 @@ def allow_only_simcore(cls, v: int) -> int:
509510
),
510511
status=status.HTTP_202_ACCEPTED,
511512
)
513+
514+
515+
@routes.post(
516+
_storage_locations_prefix + "/{location_id}/search", name="search"
517+
)
518+
@login_required
519+
@permission_required("storage.files.*")
520+
@handle_export_data_exceptions
521+
async def search(request: web.Request) -> web.Response:
522+
class _PathParams(BaseModel):
523+
location_id: LocationID
524+
525+
@field_validator("location_id")
526+
@classmethod
527+
def allow_only_simcore(cls, v: int) -> int:
528+
if v != 0:
529+
msg = f"Only simcore (location_id='0'), provided location_id='{v}' is not allowed"
530+
raise ValueError(msg)
531+
return v
532+
533+
rabbitmq_rpc_client = get_rabbitmq_rpc_client(request.app)
534+
_req_ctx = AuthenticatedRequestContext.model_validate(request)
535+
_ = parse_request_path_parameters_as(_PathParams, request)
536+
search_body = await parse_request_body_as(
537+
model_schema_cls=SearchBodyParams, request=request
538+
)
539+
async_job_rpc_get, _ = await start_search(
540+
rabbitmq_rpc_client=rabbitmq_rpc_client,
541+
user_id=_req_ctx.user_id,
542+
product_name=_req_ctx.product_name,
543+
name_pattern=search_body.name_pattern,
544+
)
545+
_job_id = f"{async_job_rpc_get.job_id}"
546+
return create_data_response(
547+
TaskGet(
548+
task_id=_job_id,
549+
status_href=f"{request.url.with_path(str(request.app.router['get_async_job_status'].url_for(task_id=_job_id)))}",
550+
abort_href=f"{request.url.with_path(str(request.app.router['cancel_async_job'].url_for(task_id=_job_id)))}",
551+
result_href=f"{request.url.with_path(str(request.app.router['get_async_job_result'].url_for(task_id=_job_id)))}",
552+
),
553+
status=status.HTTP_202_ACCEPTED,
554+
)

0 commit comments

Comments
 (0)