Skip to content

Commit

Permalink
mypying
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Apr 11, 2023
1 parent ec88da5 commit 5b6ad9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
16 changes: 12 additions & 4 deletions services/storage/src/simcore_service_storage/handlers_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
parse_request_path_parameters_as,
parse_request_query_parameters_as,
)
from servicelib.json_serialization import json_dumps

# Exclusive for simcore-s3 storage -----------------------
from ._meta import api_vtag
Expand All @@ -26,8 +27,10 @@
UPLOAD_TASKS_KEY = f"{__name__}.upload_tasks"


@routes.get(f"/{api_vtag}/locations/{{location_id}}/datasets", name="get_datasets_metadata") # type: ignore
async def get_datasets_metadata(request: web.Request):
@routes.get(
f"/{api_vtag}/locations/{{location_id}}/datasets", name="get_datasets_metadata"
)
async def get_datasets_metadata(request: web.Request) -> web.Response:
query_params = parse_request_query_parameters_as(StorageQueryParamsBase, request)
path_params = parse_request_path_parameters_as(LocationPathParams, request)
log.debug(
Expand All @@ -36,7 +39,9 @@ async def get_datasets_metadata(request: web.Request):
)

dsm = get_dsm_provider(request.app).get(path_params.location_id)
return await dsm.list_datasets(query_params.user_id)
return web.json_response(
{"data": await dsm.list_datasets(query_params.user_id)}, dumps=json_dumps
)


@routes.get(f"/{api_vtag}/locations/{{location_id}}/datasets/{{dataset_id}}/metadata", name="get_files_metadata_dataset") # type: ignore
Expand All @@ -54,4 +59,7 @@ async def get_files_metadata_dataset(request: web.Request):
user_id=query_params.user_id,
dataset_id=path_params.dataset_id,
)
return [jsonable_encoder(FileMetaDataGet.from_orm(d)) for d in data]
return web.json_response(
{"data": [jsonable_encoder(FileMetaDataGet.from_orm(d)) for d in data]},
dumps=json_dumps,
)
19 changes: 12 additions & 7 deletions services/storage/src/simcore_service_storage/handlers_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ async def get_file_metadata(request: web.Request) -> web.Response:
# NOTE: This is what happens Larry... data must be an empty {} or else some old
# dynamic services will FAIL (sic)
# TODO: once all legacy services are gone, remove the try except, it will default to 404
return web.json_response({"error": "No result found", "data": {}})
return web.json_response(
{"error": "No result found", "data": {}}, dumps=json_dumps
)

if request.headers.get("User-Agent") == "OpenAPI-Generator/0.1.0/python":
# LEGACY compatiblity with API v0.1.0
Expand All @@ -119,7 +121,8 @@ async def get_file_metadata(request: web.Request) -> web.Response:
"user_name": None,
},
"error": None,
}
},
dumps=json_dumps,
)

return jsonable_encoder(FileMetaDataGet.from_orm(data))
Expand All @@ -139,7 +142,7 @@ async def download_file(request: web.Request) -> web.Response:
link = await dsm.create_file_download_link(
query_params.user_id, path_params.file_id, query_params.link_type
)
return web.json_response({"link": link})
return web.json_response({"data": {"link": link}}, dumps=json_dumps)


@routes.put(
Expand Down Expand Up @@ -188,7 +191,8 @@ async def upload_file(request: web.Request) -> web.Response:
# return v1 response
assert len(links.urls) == 1 # nosec
return web.json_response(
{"link": jsonable_encoder(links.urls[0], by_alias=True)}
{"data": {"link": jsonable_encoder(links.urls[0], by_alias=True)}},
dumps=json_dumps,
)

# v2 response
Expand Down Expand Up @@ -227,7 +231,7 @@ async def upload_file(request: web.Request) -> web.Response:
f"/{api_vtag}/locations/{{location_id}}/files/{{file_id}}:abort",
name="abort_upload_file",
)
async def abort_upload_file(request: web.Request):
async def abort_upload_file(request: web.Request) -> NoReturn:
query_params = parse_request_query_parameters_as(StorageQueryParamsBase, request)
path_params = parse_request_path_parameters_as(FilePathParams, request)
log.debug(
Expand All @@ -244,7 +248,7 @@ async def abort_upload_file(request: web.Request):
f"/{api_vtag}/locations/{{location_id}}/files/{{file_id}}:complete",
name="complete_upload_file",
)
async def complete_upload_file(request: web.Request):
async def complete_upload_file(request: web.Request) -> web.Response:
query_params = parse_request_query_parameters_as(StorageQueryParamsBase, request)
path_params = parse_request_path_parameters_as(FilePathParams, request)
body = await parse_request_body_as(FileUploadCompletionBody, request)
Expand Down Expand Up @@ -282,14 +286,15 @@ async def complete_upload_file(request: web.Request):
return web.json_response(
status=web.HTTPAccepted.status_code,
data={"data": jsonable_encoder(response, by_alias=True)},
dumps=json_dumps,
)


@routes.post(
f"/{api_vtag}/locations/{{location_id}}/files/{{file_id}}:complete/futures/{{future_id}}",
name="is_completed_upload_file",
)
async def is_completed_upload_file(request: web.Request):
async def is_completed_upload_file(request: web.Request) -> web.Response:
query_params = parse_request_query_parameters_as(StorageQueryParamsBase, request)
path_params = parse_request_path_parameters_as(
FilePathIsUploadCompletedParams, request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
parse_request_path_parameters_as,
parse_request_query_parameters_as,
)
from servicelib.json_serialization import json_dumps
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
from settings_library.s3 import S3Settings
from simcore_service_storage.dsm import get_dsm_provider
Expand Down Expand Up @@ -48,7 +49,7 @@ async def get_or_create_temporary_s3_access(request: web.Request) -> web.Respons
s3_settings: S3Settings = await sts.get_or_create_temporary_token_for_user(
request.app, query_params.user_id
)
return web.json_response({"data": s3_settings.dict()})
return web.json_response({"data": s3_settings.dict()}, dumps=json_dumps)


async def _copy_folders_from_project(
Expand Down Expand Up @@ -136,5 +137,6 @@ async def search_files_starting_with(request: web.Request) -> web.Response:
log.debug("Found %d files starting with '%s'", len(data), query_params.startswith)

return web.json_response(
[jsonable_encoder(FileMetaDataGet.from_orm(d)) for d in data]
{"data": [jsonable_encoder(FileMetaDataGet.from_orm(d)) for d in data]},
dumps=json_dumps,
)

0 comments on commit 5b6ad9e

Please sign in to comment.