from pydantic import BaseModel from pydantic_settings import ( BaseSettings, SettingsConfigDict, ) from pathlib import Path import logging BASE_DIR = Path(__file__).parent TEMPLATES_DIR = BASE_DIR / "web" / "templates" STATIC_DIR = BASE_DIR / "web" / "static" class RunConfig(BaseModel): host: str port: int reload: bool class SwaggerConfig(BaseModel): openapi_url: str = "/openapi.json" title: str = "Netadm API" oauth2_redirect_url: str = "/docs/oauth2-redirect" swagger_js_url: str = "/static/swagger/swagger-ui-bundle.js" swagger_css_url: str = "/static/swagger/swagger-ui.css" swagger_favicon_url: str = "/static/swagger/favicon.png" class Settings(BaseSettings): model_config = SettingsConfigDict( env_file=( BASE_DIR / ".env-template", BASE_DIR / ".env", ), case_sensitive=False, env_nested_delimiter="__", env_prefix="NETADM_CONFIG__", ) run: RunConfig swagger: SwaggerConfig = SwaggerConfig() settings = Settings() def config_logging(level=logging.INFO): logging.basicConfig( level=level, datefmt="%Y-%m-%d %H:%M:%S", format="[%(asctime)s.%(msecs)03d] %(module)-25s:%(lineno)4d | %(funcName)-20s| %(levelname)-8s | %(message)s", ) config_logging(level=logging.INFO)