Refine Engine configuration wiring

This commit is contained in:
2025-10-22 05:20:23 -06:00
parent 6a3785b82f
commit fbaca54be8
6 changed files with 84 additions and 28 deletions

View File

@@ -2,11 +2,22 @@
from __future__ import annotations
from .environment import EngineSettings, load_environment
from .environment import (
DatabaseSettings,
EngineSettings,
FlaskSettings,
ServerSettings,
SocketIOSettings,
load_environment,
)
from .logging import configure_logging
__all__ = [
"DatabaseSettings",
"EngineSettings",
"FlaskSettings",
"load_environment",
"ServerSettings",
"SocketIOSettings",
"configure_logging",
]

View File

@@ -8,18 +8,47 @@ from pathlib import Path
from typing import Iterable, Tuple
@dataclass(frozen=True, slots=True)
class DatabaseSettings:
"""SQLite database configuration for the Engine."""
path: Path
@dataclass(frozen=True, slots=True)
class FlaskSettings:
"""Parameters that influence Flask application behavior."""
secret_key: str
static_root: Path
cors_allowed_origins: Tuple[str, ...]
@dataclass(frozen=True, slots=True)
class SocketIOSettings:
"""Configuration for the optional Socket.IO server."""
cors_allowed_origins: Tuple[str, ...]
@dataclass(frozen=True, slots=True)
class ServerSettings:
"""HTTP server binding configuration."""
host: str
port: int
@dataclass(frozen=True, slots=True)
class EngineSettings:
"""Immutable container describing the Engine runtime configuration."""
project_root: Path
database_path: Path
static_root: Path
cors_allowed_origins: Tuple[str, ...]
secret_key: str
debug: bool
host: str
port: int
database: DatabaseSettings
flask: FlaskSettings
socketio: SocketIOSettings
server: ServerSettings
@property
def logs_root(self) -> Path:
@@ -27,6 +56,12 @@ class EngineSettings:
return self.project_root / "Logs" / "Server"
@property
def database_path(self) -> Path:
"""Convenience accessor for the database file path."""
return self.database.path
def _resolve_project_root() -> Path:
candidate = os.getenv("BOREALIS_ROOT")
@@ -61,27 +96,37 @@ def load_environment() -> EngineSettings:
"""Load Engine settings from environment variables and filesystem hints."""
project_root = _resolve_project_root()
database_path = _resolve_database_path(project_root)
static_root = _resolve_static_root(project_root)
database = DatabaseSettings(path=_resolve_database_path(project_root))
cors_allowed_origins = _parse_origins(os.getenv("BOREALIS_CORS_ALLOWED_ORIGINS"))
secret_key = os.getenv("BOREALIS_FLASK_SECRET_KEY", "change-me")
flask_settings = FlaskSettings(
secret_key=os.getenv("BOREALIS_FLASK_SECRET_KEY", "change-me"),
static_root=_resolve_static_root(project_root),
cors_allowed_origins=cors_allowed_origins,
)
socket_settings = SocketIOSettings(cors_allowed_origins=cors_allowed_origins)
debug = os.getenv("BOREALIS_DEBUG", "false").lower() in {"1", "true", "yes", "on"}
host = os.getenv("BOREALIS_HOST", "127.0.0.1")
try:
port = int(os.getenv("BOREALIS_PORT", "5000"))
except ValueError:
port = 5000
server_settings = ServerSettings(host=host, port=port)
return EngineSettings(
project_root=project_root,
database_path=database_path,
static_root=static_root,
cors_allowed_origins=cors_allowed_origins,
secret_key=secret_key,
debug=debug,
host=host,
port=port,
database=database,
flask=flask_settings,
socketio=socket_settings,
server=server_settings,
)
__all__ = ["EngineSettings", "load_environment"]
__all__ = [
"DatabaseSettings",
"EngineSettings",
"FlaskSettings",
"SocketIOSettings",
"ServerSettings",
"load_environment",
]