Skip to content

Commit

Permalink
tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 11, 2024
1 parent d5fc4bc commit d3a221d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/specs/web-server/_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from simcore_service_webserver.users._notifications_handlers import (
_NotificationPathParams,
)
from simcore_service_webserver.users._tokens_handlers import _TokenPathParams
from simcore_service_webserver.users._tokens_rest import _TokenPathParams
from simcore_service_webserver.users.common._schemas import PreRegisteredUserGet

router = APIRouter(prefix=f"/{API_VTAG}", tags=["user"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class InputSchema(BaseModel):
)


class OutputSchemaWithoutCamelCase(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
extra="ignore",
frozen=True,
)


class OutputSchema(BaseModel):
model_config = ConfigDict(
alias_generator=snake_to_camel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
UserPermission,
UserThirdPartyToken,
)
from ._base import InputSchema, InputSchemaWithoutCamelCase, OutputSchema
from ._base import (
InputSchema,
InputSchemaWithoutCamelCase,
OutputSchema,
OutputSchemaWithoutCamelCase,
)
from .groups import MyGroupsGet
from .users_preferences import AggregatedPreferences

Expand Down Expand Up @@ -224,7 +229,7 @@ def to_model(self) -> UserThirdPartyToken:
)


class MyTokenGet(OutputSchema):
class MyTokenGet(OutputSchemaWithoutCamelCase):
service: str
token_key: UUID
token_secret: Annotated[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..login.decorators import login_required
from ..security.decorators import permission_required
from ..utils_aiohttp import envelope_json_response
from . import _tokens
from . import _tokens_service
from .common._schemas import UsersRequestContext
from .exceptions import TokenNotFoundError

Expand Down Expand Up @@ -45,7 +45,7 @@ async def _wrapper(request: web.Request) -> web.StreamResponse:
@permission_required("user.tokens.*")
async def list_tokens(request: web.Request) -> web.Response:
req_ctx = UsersRequestContext.model_validate(request)
all_tokens = await _tokens.list_tokens(request.app, req_ctx.user_id)
all_tokens = await _tokens_service.list_tokens(request.app, req_ctx.user_id)
return envelope_json_response([MyTokenGet.from_model(t) for t in all_tokens])


Expand All @@ -57,7 +57,7 @@ async def create_token(request: web.Request) -> web.Response:
req_ctx = UsersRequestContext.model_validate(request)
token_create = await parse_request_body_as(MyTokenCreate, request)

token = await _tokens.create_token(
token = await _tokens_service.create_token(
request.app, req_ctx.user_id, token_create.to_model()
)

Expand All @@ -76,7 +76,7 @@ async def get_token(request: web.Request) -> web.Response:
req_ctx = UsersRequestContext.model_validate(request)
req_path_params = parse_request_path_parameters_as(_TokenPathParams, request)

token = await _tokens.get_token(
token = await _tokens_service.get_token(
request.app, req_ctx.user_id, req_path_params.service
)

Expand All @@ -91,6 +91,8 @@ async def delete_token(request: web.Request) -> web.Response:
req_ctx = UsersRequestContext.model_validate(request)
req_path_params = parse_request_path_parameters_as(_TokenPathParams, request)

await _tokens.delete_token(request.app, req_ctx.user_id, req_path_params.service)
await _tokens_service.delete_token(
request.app, req_ctx.user_id, req_path_params.service
)

return web.json_response(status=status.HTTP_204_NO_CONTENT)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
import sqlalchemy as sa
from aiohttp import web
from models_library.api_schemas_webserver.users import UserThirdPartyToken
from models_library.users import UserID, UserThirdPartyToken
from models_library.utils.fastapi_encoders import jsonable_encoder
from sqlalchemy import and_, literal_column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
from servicelib.aiohttp.application_setup import ModuleCategory, app_module_setup
from servicelib.aiohttp.observer import setup_observer_registry

from . import (
_notifications_handlers,
_preferences_handlers,
_tokens_handlers,
_users_rest,
)
from . import _notifications_handlers, _preferences_handlers, _tokens_rest, _users_rest
from ._preferences_models import overwrite_user_preferences_defaults

_logger = logging.getLogger(__name__)
Expand All @@ -33,6 +28,6 @@ def setup_users(app: web.Application):
overwrite_user_preferences_defaults(app)

app.router.add_routes(_users_rest.routes)
app.router.add_routes(_tokens_handlers.routes)
app.router.add_routes(_tokens_rest.routes)
app.router.add_routes(_notifications_handlers.routes)
app.router.add_routes(_preferences_handlers.routes)

0 comments on commit d3a221d

Please sign in to comment.