Skip to content

Commit

Permalink
♻️ Enhancement/storage refactoring part 1 (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored May 30, 2022
1 parent 4ef961e commit 9ea5d8d
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 294 deletions.
28 changes: 9 additions & 19 deletions api/specs/storage/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ paths:
default:
$ref: "#/components/responses/DefaultErrorResponse"

/locations/{location_id}/files/{fileId}/metadata:
/locations/{location_id}/files/{file_id}/metadata:
get:
summary: Get file metadata
operationId: get_file_metadata
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand Down Expand Up @@ -247,7 +247,7 @@ paths:
summary: Update file metadata
operationId: update_file_meta_data
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -272,12 +272,12 @@ paths:
default:
$ref: "#/components/responses/DefaultErrorResponse"

/locations/{location_id}/files/{fileId}:
/locations/{location_id}/files/{file_id}:
get:
summary: Gets download link for file at location
operationId: download_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand Down Expand Up @@ -312,10 +312,10 @@ paths:
default:
$ref: "#/components/responses/DefaultErrorResponse"
put:
summary: Returns upload link or performs copy operation to datcore
summary: Returns upload object
operationId: upload_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -330,16 +330,6 @@ paths:
required: true
schema:
type: string
- name: extra_location
in: query
required: false
schema:
type: string
- name: extra_source
in: query
required: false
schema:
type: string
- name: link_type
in: query
required: false
Expand All @@ -362,7 +352,7 @@ paths:
summary: Deletes file
operationId: delete_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -379,7 +369,7 @@ paths:
type: string
responses:
"204":
description: everything is OK, but there is no content to return
description: everything is OK
default:
$ref: "#/components/responses/DefaultErrorResponse"

Expand Down
26 changes: 8 additions & 18 deletions api/specs/webserver/openapi-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ paths:
default:
$ref: "#/components/responses/DefaultErrorResponse"

/storage/locations/{location_id}/files/{fileId}:
/storage/locations/{location_id}/files/{file_id}:
get:
summary: Returns download link for requested file
tags:
- storage
operationId: download_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -141,12 +141,12 @@ paths:
"200":
$ref: "#/components/responses/PresignedLink_200"
put:
summary: Returns upload link or performs copy operation to datcore
summary: Returns upload link
tags:
- storage
operationId: upload_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -156,16 +156,6 @@ paths:
required: true
schema:
type: string
- name: extra_location
in: query
required: false
schema:
type: string
- name: extra_source
in: query
required: false
schema:
type: string
responses:
"200":
$ref: "#/components/responses/PresignedLink_200"
Expand All @@ -175,7 +165,7 @@ paths:
- storage
operationId: delete_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -189,14 +179,14 @@ paths:
"204":
description: ""

/storage/locations/{location_id}/files/{fileId}/metadata:
/storage/locations/{location_id}/files/{file_id}/metadata:
get:
summary: Get File Metadata
tags:
- storage
operationId: get_file_metadata
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -215,7 +205,7 @@ paths:
- storage
operationId: update_file_meta_data
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand Down
8 changes: 4 additions & 4 deletions api/specs/webserver/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ paths:
/storage/locations/{location_id}/files/metadata:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1files~1metadata"

/storage/locations/{location_id}/files/{fileId}:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1files~1{fileId}"
/storage/locations/{location_id}/files/{file_id}:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1files~1{file_id}"

/storage/locations/{location_id}/files/{fileId}/metadata:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1files~1{fileId}~1metadata"
/storage/locations/{location_id}/files/{file_id}/metadata:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1files~1{file_id}~1metadata"

/storage/locations/{location_id}/datasets/{dataset_id}/metadata:
$ref: "./openapi-storage.yaml#/paths/~1storage~1locations~1{location_id}~1datasets~1{dataset_id}~1metadata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Config:


# /locations/{location_id}/files/metadata:
# /locations/{location_id}/files/{fileId}/metadata:
# /locations/{location_id}/files/{file_id}/metadata:
class FileMetaData(BaseModel):
file_uuid: Optional[str] = Field(
description="Unique identifier for a file, like bucket_name/project_id/node_id/file_name = /bucket_name/object_name",
Expand Down Expand Up @@ -189,7 +189,7 @@ class FileMetaDataArray(BaseModel):
__root__: List[FileMetaData] = []


# /locations/{location_id}/files/{fileId}
# /locations/{location_id}/files/{file_id}


class PresignedLink(BaseModel):
Expand Down
14 changes: 7 additions & 7 deletions services/storage/src/simcore_service_storage/access_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import logging
from dataclasses import dataclass
from typing import Dict, List, Optional
from typing import Optional
from uuid import UUID

import sqlalchemy as sa
Expand Down Expand Up @@ -89,15 +89,15 @@ def __str__(self):
return "Error in {}: {} [{}]".format(self.identifier, self.reason, self.details)


async def _get_user_groups_ids(conn: SAConnection, user_id: int) -> List[int]:
async def _get_user_groups_ids(conn: SAConnection, user_id: int) -> list[int]:
stmt = sa.select([user_to_groups.c.gid]).where(user_to_groups.c.uid == user_id)
rows = await (await conn.execute(stmt)).fetchall()
user_group_ids = [g.gid for g in rows]
return user_group_ids


def _aggregate_access_rights(
access_rights: Dict[str, Dict], group_ids: List[int]
access_rights: dict[str, dict], group_ids: list[int]
) -> AccessRights:
try:
prj_access = {"read": False, "write": False, "delete": False}
Expand All @@ -118,12 +118,12 @@ def _aggregate_access_rights(

async def list_projects_access_rights(
conn: SAConnection, user_id: int
) -> Dict[ProjectID, AccessRights]:
) -> dict[ProjectID, AccessRights]:
"""
Returns access-rights of user (user_id) over all OWNED or SHARED projects
"""

user_group_ids: List[int] = await _get_user_groups_ids(conn, user_id)
user_group_ids: list[int] = await _get_user_groups_ids(conn, user_id)

smt = text(
f"""\
Expand Down Expand Up @@ -164,7 +164,7 @@ async def get_project_access_rights(
"""
Returns access-rights of user (user_id) over a project resource (project_id)
"""
user_group_ids: List[int] = await _get_user_groups_ids(conn, user_id)
user_group_ids: list[int] = await _get_user_groups_ids(conn, user_id)

stmt = text(
f"""\
Expand Down Expand Up @@ -281,7 +281,7 @@ async def get_file_access_rights(
# HELPERS -----------------------------------------------


async def get_readable_project_ids(conn: SAConnection, user_id: int) -> List[ProjectID]:
async def get_readable_project_ids(conn: SAConnection, user_id: int) -> list[ProjectID]:
"""Returns a list of projects where user has granted read-access"""
projects_access_rights = await list_projects_access_rights(conn, int(user_id))
return [pid for pid, access in projects_access_rights.items() if access.read]
28 changes: 9 additions & 19 deletions services/storage/src/simcore_service_storage/api/v0/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ paths:
$ref: '#/components/schemas/FileMetaDataArrayEnveloped'
default:
$ref: '#/components/responses/DefaultErrorResponse'
'/locations/{location_id}/files/{fileId}/metadata':
'/locations/{location_id}/files/{file_id}/metadata':
get:
summary: Get file metadata
operationId: get_file_metadata
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand Down Expand Up @@ -241,7 +241,7 @@ paths:
summary: Update file metadata
operationId: update_file_meta_data
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -265,12 +265,12 @@ paths:
$ref: '#/components/schemas/FileMetaEnvelope'
default:
$ref: '#/components/responses/DefaultErrorResponse'
'/locations/{location_id}/files/{fileId}':
'/locations/{location_id}/files/{file_id}':
get:
summary: Gets download link for file at location
operationId: download_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand Down Expand Up @@ -304,10 +304,10 @@ paths:
default:
$ref: '#/components/responses/DefaultErrorResponse'
put:
summary: Returns upload link or performs copy operation to datcore
summary: Returns upload object
operationId: upload_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -322,16 +322,6 @@ paths:
required: true
schema:
type: string
- name: extra_location
in: query
required: false
schema:
type: string
- name: extra_source
in: query
required: false
schema:
type: string
- name: link_type
in: query
required: false
Expand All @@ -354,7 +344,7 @@ paths:
summary: Deletes file
operationId: delete_file
parameters:
- name: fileId
- name: file_id
in: path
required: true
schema:
Expand All @@ -371,7 +361,7 @@ paths:
type: string
responses:
'204':
description: 'everything is OK, but there is no content to return'
description: everything is OK
default:
$ref: '#/components/responses/DefaultErrorResponse'
'/simcore-s3:access':
Expand Down
Loading

0 comments on commit 9ea5d8d

Please sign in to comment.