-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import List, Optional | ||
|
||
from attr import __description__ | ||
from fastapi import APIRouter, FastAPI | ||
from models_library.api_schemas_storage import HealthCheckEnveloped | ||
from models_library.app_diagnostics import AppStatusCheck | ||
from pydantic import BaseModel, HttpUrl | ||
from simcore_service_storage.meta import api_version_prefix | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/", response_model=HealthCheckEnveloped, operation_id="get_health") | ||
def get_app_health(): | ||
pass | ||
|
||
|
||
@router.get("/status", response_model=AppStatusCheck) | ||
def get_app_status(): | ||
pass | ||
|
||
|
||
files_router = APIRouter() | ||
|
||
|
||
class ApiResource(BaseModel): | ||
id: str | ||
|
||
# self url | ||
url: HttpUrl | ||
|
||
|
||
class File(ApiResource): | ||
storage_source: str # simcore/datcore/google drive etc | ||
title: Optional[str] | ||
|
||
|
||
class FileEdit(File): | ||
# nothing is required | ||
pass | ||
|
||
|
||
class FileList(BaseModel): | ||
items: List[File] | ||
# tokens ... | ||
|
||
|
||
@files_router.get("", response_model=FileList) | ||
def list_files(): | ||
""" Lists the user's files """ | ||
|
||
|
||
@files_router.post("/{file_id}", response_model=File) | ||
def get_file(): | ||
""" Gets a file's metadata or content by id""" | ||
|
||
|
||
@files_router.post("/{file_id:path}:copy", response_model=File) | ||
def copy_file( | ||
file_id: str, | ||
as_soft_link: bool = False, | ||
new_file: Optional[FileEdit] = None, | ||
): | ||
""" Creates a copy of a specified file """ | ||
print(file_id, as_soft_link, new_file) | ||
|
||
|
||
app = FastAPI() | ||
app.include_router(router, prefix="/v1") | ||
app.include_router(files_router, prefix="/v1/files", tags=["files"]) | ||
|
||
|
||
def main(): | ||
# uvicorn openapi_generator:app --reload --host 0.0.0.0 | ||
print(json.dumps(app.openapi(), indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
66 changes: 66 additions & 0 deletions
66
services/storage/src/simcore_service_storage/files_handlers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
import sqlalchemy as sa | ||
from aiohttp.web import Request, RouteTableDef | ||
from servicelib.rest_utils import extract_and_validate | ||
from simcore_service_storage.handlers import get_file_metadata | ||
|
||
from .files_models import File, FileEdit | ||
from .meta import api_version, api_version_prefix, app_name | ||
from .models import file_meta_data | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
routes = RouteTableDef() | ||
|
||
|
||
class UserDrive: | ||
def __init__(self, user_id, engine): | ||
self.engine = engine | ||
|
||
# async def create_soft_link( | ||
# file_id: str, | ||
# new_file_id: str, | ||
# ) -> File: | ||
|
||
# async with self.engine.acquire() as conn, conn.begin(): | ||
|
||
# stmt = file_meta_data.insert([])where( | ||
# file_meta_data.c.file_uuid.startswith(prefix) & has_read_access | ||
# ) | ||
|
||
|
||
@routes.post("/{file_id}:copy", name="copy_file") # type: ignore | ||
async def copy_file_handler(request: Request): | ||
|
||
# TODO: access rights? | ||
|
||
# TODO: validate request | ||
|
||
# TODO: transform into arguments and context | ||
user_id = request.query["user_id"] | ||
|
||
async def copy_file( | ||
file_id: str, | ||
as_soft_link: bool = False, | ||
new_file: Optional[FileEdit] = None, | ||
) -> File: | ||
""" Creates a copy of a specified file """ | ||
|
||
# | ||
# find file_id row | ||
# clone and | ||
# - rename file_uuid with new_file.id | ||
# - change time-stamp of creation | ||
# - inherits user_id | ||
|
||
print(file_id, as_soft_link, new_file) | ||
|
||
raise NotImplementedError() | ||
|
||
# copy: File = await copy_file(file_id, as_soft_link=, new_file=) | ||
|
||
# TODO: transform return into response | ||
# TODO: handler errors |
29 changes: 29 additions & 0 deletions
29
services/storage/src/simcore_service_storage/files_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Model schemas for storage's API | ||
Used in requests associated to the files resource | ||
""" | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel, HttpUrl | ||
|
||
|
||
class ApiResource(BaseModel): | ||
id: str | ||
|
||
# self url | ||
url: HttpUrl | ||
|
||
|
||
class File(ApiResource): | ||
storage_source: str # simcore/datcore/google drive etc | ||
title: Optional[str] | ||
|
||
|
||
class FileEdit(File): | ||
# nothing is required | ||
pass | ||
|
||
|
||
class FileList(BaseModel): | ||
items: List[File] | ||
# tokens ... |
25 changes: 25 additions & 0 deletions
25
services/storage/src/simcore_service_storage/utils_handlers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" This module is to encourage reusing common functionality on handler modules | ||
Drop here any helper function commonly used in handler modules and that has no other place to | ||
be. Later could be moved to a more convenient module | ||
""" | ||
|
||
from aiohttp.web import Request | ||
from servicelib.rest_utils import extract_and_validate | ||
|
||
from .dsm import DataStorageManager | ||
|
||
|
||
def create_storage_manager( | ||
request: Request, | ||
): | ||
|
||
# TODO: minimum to request | ||
|
||
DataStorageManager() | ||
|
||
|
||
async def validate_request(request: Request): | ||
params, query, body = await extract_and_validate(request) | ||
|
||
dsm = await _prepare_storage_manager(params, query, request) |