Initial commit

This commit is contained in:
2026-02-15 16:28:38 +00:00
commit 0e793197bf
24 changed files with 3268 additions and 0 deletions

45
app/config.py Normal file
View File

@@ -0,0 +1,45 @@
import os
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
@dataclass(frozen=True)
class AppConfig:
app_username: str
app_password: str
app_password_hash: str | None
session_secret: str
database_path: Path
request_timeout_seconds: int
session_cookie_secure: bool
metrics_sampler_interval_seconds: int
def _bool_env(name: str, default: bool) -> bool:
value = os.getenv(name)
if value is None:
return default
return value.strip().lower() in {"1", "true", "yes", "on"}
@lru_cache(maxsize=1)
def get_config() -> AppConfig:
data_dir = Path(os.getenv("DATA_DIR", "./data"))
data_dir.mkdir(parents=True, exist_ok=True)
return AppConfig(
app_username=os.getenv("APP_USERNAME", "admin"),
app_password=os.getenv("APP_PASSWORD", "changeme"),
app_password_hash=os.getenv("APP_PASSWORD_HASH"),
session_secret=os.getenv("SESSION_SECRET", "change-this-secret"),
database_path=Path(os.getenv("DB_PATH", str(data_dir / "dashboard.db"))),
request_timeout_seconds=int(os.getenv("RPC_TIMEOUT_SECONDS", "15")),
session_cookie_secure=_bool_env("SESSION_COOKIE_SECURE", False),
metrics_sampler_interval_seconds=max(15, int(os.getenv("METRICS_SAMPLER_INTERVAL_SECONDS", "60"))),
)