45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import secrets
|
|
|
|
from dotenv import load_dotenv
|
|
from pydantic import PostgresDsn, model_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# openssl rand -hex 32
|
|
TITLE: str = ""
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
MIDDLEWARE_SECRET_KEY: str = secrets.token_urlsafe(5)
|
|
ALGORITHM: str = "HS256"
|
|
JWT_TOKEN_EXPIRE_MINUTES: int = 30
|
|
HOST: str = "0.0.0.0"
|
|
PORT: int = 80
|
|
DEBUG: bool = False
|
|
LOG_LEVEL: str = "NOTSET"
|
|
POSTGRES_SERVER: str = ""
|
|
POSTGRES_USER: str = "postgres"
|
|
POSTGRES_PASSWORD: str = ""
|
|
POSTGRES_DB: str = ""
|
|
SQLALCHEMY_DATABASE_URI: str | None = None
|
|
|
|
@model_validator(mode="after")
|
|
def assemble_db_connection(self) -> "Settings":
|
|
if isinstance(self.SQLALCHEMY_DATABASE_URI, str):
|
|
return self
|
|
self.SQLALCHEMY_DATABASE_URI = PostgresDsn.build(
|
|
scheme="postgresql",
|
|
username=self.POSTGRES_USER,
|
|
password=self.POSTGRES_PASSWORD,
|
|
host=self.POSTGRES_SERVER,
|
|
path=f"/{self.POSTGRES_DB or ''}",
|
|
)
|
|
return self
|
|
|
|
ALEMBIC_LOG_LEVEL: str = "INFO"
|
|
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"
|
|
model_config = SettingsConfigDict(case_sensitive=True, env_file=".env")
|
|
|
|
|
|
load_dotenv()
|
|
settings = Settings()
|