-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathset_user_password.py
More file actions
63 lines (53 loc) · 2.16 KB
/
set_user_password.py
File metadata and controls
63 lines (53 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from inspect import getdoc
from typing import Annotated
from uuid import UUID
from dishka import FromDishka
from dishka.integrations.fastapi import inject
from fastapi import APIRouter, Path
from fastapi_error_map import ErrorAwareRouter
from pydantic import BaseModel, ConfigDict
from starlette import status
from app.core.commands.exceptions import UserNotFoundError
from app.core.commands.set_user_password import SetUserPassword, SetUserPasswordRequest
from app.core.common.authorization.exceptions import AuthorizationError
from app.core.common.exceptions import BusinessTypeError
from app.inbound.http.errors.callbacks import log_info
from app.inbound.http.errors.rules import HTTP_503_SERVICE_UNAVAILABLE_RULE
from app.outbound.adapters.exceptions import PasswordHasherBusyError
from app.outbound.auth_ctx.exceptions import AuthenticationError
from app.outbound.exceptions import StorageError
class SetUserPasswordRequestSchema(BaseModel):
"""
Using Pydantic model here is generally unnecessary.
It's only implemented to render specific Swagger UI.
"""
model_config = ConfigDict(frozen=True)
password: str
def make_set_user_password_router() -> APIRouter:
router = ErrorAwareRouter()
@router.put(
"/{user_id}/password/",
error_map={
AuthenticationError: status.HTTP_401_UNAUTHORIZED,
StorageError: HTTP_503_SERVICE_UNAVAILABLE_RULE,
AuthorizationError: status.HTTP_403_FORBIDDEN,
BusinessTypeError: status.HTTP_400_BAD_REQUEST,
UserNotFoundError: status.HTTP_404_NOT_FOUND,
PasswordHasherBusyError: HTTP_503_SERVICE_UNAVAILABLE_RULE,
},
default_on_error=log_info,
status_code=status.HTTP_204_NO_CONTENT,
description=getdoc(SetUserPassword),
)
@inject
async def set_user_password(
user_id: Annotated[UUID, Path()],
request_schema: SetUserPasswordRequestSchema,
interactor: FromDishka[SetUserPassword],
) -> None:
request = SetUserPasswordRequest(
user_id=user_id,
password=request_schema.password,
)
await interactor.execute(request)
return router