"""Minimal runtime settings; administrator and host settings live in the panel UI.""" from __future__ import annotations import os from dataclasses import dataclass from pathlib import Path PROJECT_DIR = Path(__file__).resolve().parent.parent DEFAULT_DATA_DIR = PROJECT_DIR / "data" @dataclass(frozen=True) class Settings: """Settings needed before the first browser-based setup step. The application creates ``data_dir`` and a one-time setup token. No administrator password, SSH key, or hypervisor address is read from an environment file. """ data_dir: Path = DEFAULT_DATA_DIR static_dir: Path = PROJECT_DIR / "static" ssh_binary: str = "ssh" secure_cookie: bool = True def validate(self) -> None: if not self.data_dir.is_absolute() or self.data_dir == Path("/"): raise ValueError("PANEL_DATA_DIR must be an absolute, dedicated directory") if not self.static_dir.is_dir(): raise ValueError(f"Static directory does not exist: {self.static_dir}") if not self.ssh_binary or "\x00" in self.ssh_binary: raise ValueError("PANEL_SSH_BINARY must name an executable") @classmethod def from_env(cls) -> "Settings": settings = cls( data_dir=Path(os.environ.get("PANEL_DATA_DIR", str(DEFAULT_DATA_DIR))), ssh_binary=os.environ.get("PANEL_SSH_BINARY", "ssh"), ) settings.validate() return settings