59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
|
|
|
|
def _env_bool(name: str, default: bool) -> bool:
|
|
raw = os.getenv(name)
|
|
if raw is None:
|
|
return default
|
|
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class RuntimeSettings:
|
|
environment: str = "development"
|
|
backend: str = "memory"
|
|
allow_ephemeral: bool = True
|
|
api_host: str = "127.0.0.1"
|
|
api_port: int = 8010
|
|
api_base: str = "http://127.0.0.1:8010"
|
|
mcp_host: str = "127.0.0.1"
|
|
mcp_port: int = 8011
|
|
mcp_transport: str = "http"
|
|
database_url: str | None = None
|
|
|
|
@classmethod
|
|
def from_env(cls) -> RuntimeSettings:
|
|
environment = os.getenv("HUB_CORE_ENV", "development")
|
|
default_ephemeral = environment in {"development", "test"}
|
|
api_host = os.getenv("HUB_CORE_API_HOST", "127.0.0.1")
|
|
api_port = int(os.getenv("HUB_CORE_API_PORT", "8010"))
|
|
return cls(
|
|
environment=environment,
|
|
backend=os.getenv("HUB_CORE_BACKEND", "memory"),
|
|
allow_ephemeral=_env_bool("HUB_CORE_ALLOW_EPHEMERAL", default_ephemeral),
|
|
api_host=api_host,
|
|
api_port=api_port,
|
|
api_base=os.getenv("HUB_CORE_API_BASE", f"http://127.0.0.1:{api_port}"),
|
|
mcp_host=os.getenv("HUB_CORE_MCP_HOST", "127.0.0.1"),
|
|
mcp_port=int(os.getenv("HUB_CORE_MCP_PORT", "8011")),
|
|
mcp_transport=os.getenv("HUB_CORE_MCP_TRANSPORT", "http"),
|
|
database_url=os.getenv("HUB_CORE_DATABASE_URL") or os.getenv("DATABASE_URL"),
|
|
)
|
|
|
|
def readiness_checks(self, store_backend: str) -> dict[str, str]:
|
|
ephemeral_allowed = store_backend != "memory" or self.allow_ephemeral
|
|
return {
|
|
"environment": self.environment,
|
|
"configured_backend": self.backend,
|
|
"active_backend": store_backend,
|
|
"ephemeral_backend": "allowed" if ephemeral_allowed else "not_allowed",
|
|
"contract": "helixforge.hub-extension/0.1.0",
|
|
}
|
|
|
|
def is_ready(self, store_backend: str) -> bool:
|
|
return self.backend == store_backend and (
|
|
store_backend != "memory" or self.allow_ephemeral
|
|
)
|