You've already forked RekomenciBackend
add lints
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from tomllib import loads
|
||||
from typing import dataclass_transform
|
||||
|
||||
from adaptix import P, Retort, loader
|
||||
|
||||
from template_project.application.common.containers import SecretString
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import sys
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Final
|
||||
|
||||
import uvicorn
|
||||
from dishka import AsyncContainer
|
||||
from dishka.integrations.fastapi import setup_dishka
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import uvicorn
|
||||
|
||||
from template_project.web_api.configuration import load_configuration
|
||||
from template_project.web_api.ioc.make import make_ioc
|
||||
@@ -35,11 +35,13 @@ LOG_CONFIG: Final = {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
yield
|
||||
await app.state.dishka_container.close()
|
||||
|
||||
|
||||
def make_asgi_application(
|
||||
ioc: AsyncContainer,
|
||||
) -> FastAPI:
|
||||
@@ -65,6 +67,7 @@ def make_asgi_application(
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def _main(
|
||||
configuration_path: Path,
|
||||
) -> None:
|
||||
@@ -83,7 +86,8 @@ def _main(
|
||||
|
||||
def main() -> None:
|
||||
if sys.platform == "win32":
|
||||
from asyncio import WindowsSelectorEventLoopPolicy
|
||||
from asyncio import WindowsSelectorEventLoopPolicy # noqa: PLC0415
|
||||
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
@@ -95,5 +99,6 @@ def main() -> None:
|
||||
args = arg_parser.parse_args()
|
||||
_main(args.configuration)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from abc import abstractmethod
|
||||
from typing import override
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
@@ -11,8 +11,7 @@ from template_project.application.user.data_gateway import UserDataGateway
|
||||
from template_project.application.user.entity import User
|
||||
from template_project.application.user.errors import UserUnauthorizedError
|
||||
|
||||
|
||||
TOKEN_TYPE = "Bearer"
|
||||
TOKEN_TYPE = "Bearer" # noqa: S105
|
||||
BEARER_SECTIONS = 2
|
||||
AUTH_HEADER = "Authorization"
|
||||
|
||||
@@ -31,7 +30,7 @@ class WebApiIdentityProvider(IdentityProvider):
|
||||
self._access_token_data_gateway = access_token_data_gateway
|
||||
self._access_token_cryptographer = access_token_cryptographer
|
||||
|
||||
@abstractmethod
|
||||
@override
|
||||
async def get_current_user(self) -> User:
|
||||
auth_tokn = self._request.headers[AUTH_HEADER]
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import AsyncIterable
|
||||
from collections.abc import AsyncIterable
|
||||
|
||||
from dishka import Provider, Scope, provide
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import argon2
|
||||
from cryptography.fernet import Fernet
|
||||
from dishka import Provider, Scope, WithParents, provide, provide_all
|
||||
from dishka import BaseScope, Provider, Scope, WithParents, provide, provide_all
|
||||
|
||||
from template_project.adapters.access_token.cryptographer import FernetAccessTokenCryptographer
|
||||
from template_project.adapters.password_utils import ArgonPasswordHasher, ArgonPasswordVerifying
|
||||
@@ -8,7 +8,7 @@ from template_project.web_api.configuration import AccessTokenConfiguration
|
||||
|
||||
|
||||
class CryptographerProvider(Provider):
|
||||
scope = Scope.APP
|
||||
scope: BaseScope | None = Scope.APP
|
||||
|
||||
@provide
|
||||
def argon_password_hasher(self) -> argon2.PasswordHasher:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from dishka import Provider, Scope, WithParents, provide, provide_all
|
||||
from dishka import BaseScope, Provider, Scope, WithParents, provide, provide_all
|
||||
|
||||
from template_project.adapters.data_gateways.access_token import DefaultAccessTokenDataGateway
|
||||
from template_project.adapters.data_gateways.user import DefaultUserDataGateway
|
||||
@@ -6,7 +6,7 @@ from template_project.adapters.unit_of_work import DefaultUnitOfWork
|
||||
|
||||
|
||||
class DataGatewayProvider(Provider):
|
||||
scope = Scope.REQUEST
|
||||
scope: BaseScope | None = Scope.REQUEST
|
||||
|
||||
unit_of_work = provide(WithParents[DefaultUnitOfWork])
|
||||
data_gateways = provide_all(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from dishka import Provider, Scope, WithParents, provide_all
|
||||
from dishka import BaseScope, Provider, Scope, WithParents, provide_all
|
||||
|
||||
from template_project.adapters.access_token.factory import DefaultAccessTokenFactory
|
||||
|
||||
|
||||
class FactoryProvider(Provider):
|
||||
scope = Scope.APP
|
||||
scope: BaseScope | None = Scope.APP
|
||||
|
||||
provides = provide_all(
|
||||
WithParents[DefaultAccessTokenFactory],
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from dishka import Provider, Scope, provide_all
|
||||
from dishka import BaseScope, Provider, Scope, provide_all
|
||||
|
||||
from template_project.application.user.interactors.sign_up import UserSignUpInteractor
|
||||
|
||||
|
||||
class InteractorProvider(Provider):
|
||||
scope = Scope.REQUEST
|
||||
scope: BaseScope | None = Scope.REQUEST
|
||||
|
||||
interactors = provide_all(
|
||||
UserSignUpInteractor,
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
from dishka import AsyncContainer, make_async_container
|
||||
from dishka.integrations.fastapi import FastapiProvider
|
||||
|
||||
from template_project.web_api.configuration import AccessTokenConfiguration, Configuration, DatabaseConfiguration, ServerConfiguration
|
||||
from template_project.web_api.configuration import (
|
||||
AccessTokenConfiguration,
|
||||
Configuration,
|
||||
DatabaseConfiguration,
|
||||
ServerConfiguration,
|
||||
)
|
||||
from template_project.web_api.ioc.cryptographer import CryptographerProvider
|
||||
from template_project.web_api.ioc.data_gateway import DataGatewayProvider
|
||||
from template_project.web_api.ioc.factory import FactoryProvider
|
||||
from template_project.web_api.ioc.interactor import InteractorProvider
|
||||
from template_project.web_api.ioc.cryptographer import CryptographerProvider
|
||||
|
||||
|
||||
def make_ioc(configuration: Configuration) -> AsyncContainer:
|
||||
|
||||
@@ -6,7 +6,6 @@ from pydantic import BaseModel, SecretStr
|
||||
from template_project.application.common.containers import SecretString
|
||||
from template_project.application.user.interactors.sign_up import UserSignUpInteractor
|
||||
|
||||
|
||||
router = APIRouter(route_class=DishkaRoute)
|
||||
|
||||
|
||||
@@ -25,8 +24,7 @@ async def sign_up(
|
||||
interactor: FromDishka[UserSignUpInteractor],
|
||||
) -> UserSignUpResponse:
|
||||
response_interactor = await interactor.execute(
|
||||
email=request.email,
|
||||
password=SecretString(request.password.get_secret_value())
|
||||
email=request.email, password=SecretString(request.password.get_secret_value())
|
||||
)
|
||||
return UserSignUpResponse(
|
||||
access_token=response_interactor.access_token,
|
||||
|
||||
Reference in New Issue
Block a user