from datetime import timedelta from fastapi import APIRouter, HTTPException from starlette import status from project.config import Config from project.dal.retailer import RetailerRepository from project.dtos.auth import Token, AuthData from project.logger import Logger from project.services.auth.auth_service import AuthService config = Config() logger = Logger() router = APIRouter() retailer_repository = RetailerRepository(config, logger) auth_service = AuthService(config, logger, retailer_repository) @router.post("/auth/token/", response_model=Token) def login_for_access_token(auth_data: AuthData) -> Token: retailer = auth_service.authenticate_retailer(email=auth_data.email, password=auth_data.password) if not retailer: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, )
def change_logger(logger_name='test'): global logger logger = Logger(logger_name)
def logger() -> Logger: return Logger()
#!/usr/bin/env python # -*- coding: utf-8 -*- import functools import traceback from project.logger import Logger logger_name = 'app' logger = Logger(logger_name) def change_logger(logger_name='test'): global logger logger = Logger(logger_name) def trace(f: callable) -> callable: """ trace decorator Args: f: decorated function Returns: wrapper function >>> fn = lambda : print("hello") >>> lg = trace(fn) >>> type(lg) <class 'function'> >>> lg.__name__ '<lambda>'
def logger(self): return Logger(logger_name)