2024-10-02 08:47:11 +00:00
|
|
|
from typing import ClassVar
|
|
|
|
|
2024-10-01 11:29:39 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
from pydantic_settings import (
|
|
|
|
BaseSettings,
|
|
|
|
SettingsConfigDict,
|
|
|
|
)
|
2024-10-01 20:06:21 +00:00
|
|
|
from pydantic import PostgresDsn
|
2024-10-01 11:29:39 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2024-10-01 12:05:49 +00:00
|
|
|
BASE_DIR = Path(__file__).parent
|
2024-10-01 14:09:19 +00:00
|
|
|
TEMPLATES_DIR = BASE_DIR / "web" / "templates"
|
|
|
|
STATIC_DIR = BASE_DIR / "web" / "static"
|
2024-10-01 11:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RunConfig(BaseModel):
|
2024-10-01 15:06:04 +00:00
|
|
|
host: str
|
|
|
|
port: int
|
|
|
|
reload: bool
|
2024-10-01 11:29:39 +00:00
|
|
|
|
|
|
|
|
2024-10-01 12:05:49 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
2024-10-01 20:06:21 +00:00
|
|
|
class DatabaseConfig(BaseModel):
|
|
|
|
url: PostgresDsn
|
|
|
|
echo: bool = False
|
|
|
|
echo_pool: bool = False
|
|
|
|
pool_size: int = 50
|
|
|
|
max_overflow: int = 10
|
|
|
|
|
|
|
|
naming_convention: dict[str, str] = {
|
|
|
|
"ix": "ix_%(column_0_label)s",
|
|
|
|
"uq": "uq_%(table_name)s_%(column_0_N_name)s",
|
|
|
|
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
|
|
|
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
|
|
|
"pk": "pk_%(table_name)s",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-02 08:47:11 +00:00
|
|
|
class TypesConfig(BaseModel):
|
|
|
|
UserIdType: ClassVar = int
|
|
|
|
|
|
|
|
|
2024-10-01 11:29:39 +00:00
|
|
|
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__",
|
|
|
|
)
|
2024-10-01 15:06:04 +00:00
|
|
|
run: RunConfig
|
2024-10-01 12:05:49 +00:00
|
|
|
swagger: SwaggerConfig = SwaggerConfig()
|
2024-10-01 20:06:21 +00:00
|
|
|
db: DatabaseConfig
|
2024-10-02 08:47:11 +00:00
|
|
|
type: TypesConfig = TypesConfig()
|
2024-10-01 11:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|