service_man/api/infrastructure/dependencies/protocols.py

37 lines
1.4 KiB
Python

from typing import Annotated
from fastapi import Depends
from api.application.protocols.date_time import DateTimeProvider
from api.application.protocols.jwt import JwtTokenProcessor
from api.application.protocols.password_hasher import PasswordHasher
from api.application.usecase.auth.auth_user import LoginUser
from api.domain.user.repository import UserRepository
from api.infrastructure.auth.jwt_processor import JoseJwtTokenProcessor
from api.infrastructure.date_time import SystemDateTimeProvider, Timezone
from api.infrastructure.dependencies.stub import Stub
from api.infrastructure.security.password_hasher import Pbkdf2PasswordHasher
from api.infrastructure.settings import Settings
def get_password_hasher() -> PasswordHasher:
return Pbkdf2PasswordHasher()
def get_date_time_provider() -> DateTimeProvider:
return SystemDateTimeProvider(Timezone.UTC)
def get_jwt_token_processor(
settings: Annotated[Settings, Depends(Stub(Settings))],
date_time_provider: Annotated[DateTimeProvider, Depends(Stub(DateTimeProvider))],
) -> JwtTokenProcessor:
return JoseJwtTokenProcessor(jwt_options=settings.jwt, date_time_provider=date_time_provider)
def get_user_login(
user_repository: Annotated[UserRepository, Depends(Stub(UserRepository))],
password_hasher: Annotated[PasswordHasher, Depends(Stub(PasswordHasher))],
) -> LoginUser:
return LoginUser(user_repository=user_repository, password_hasher=password_hasher)