43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""Startup-cached, non-secret application metadata."""
|
|
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from alembic.config import Config
|
|
from alembic.script import ScriptDirectory
|
|
|
|
from app.config import settings
|
|
|
|
|
|
def _clean_build_value(value: str | None) -> str | None:
|
|
if value is None:
|
|
return None
|
|
cleaned = value.strip()
|
|
return cleaned[:128] if cleaned else None
|
|
|
|
|
|
def _expected_migration_head() -> str | None:
|
|
try:
|
|
backend_root = Path(__file__).resolve().parents[2]
|
|
config = Config(str(backend_root / "alembic.ini"))
|
|
config.set_main_option("script_location", str(backend_root / "alembic"))
|
|
return ScriptDirectory.from_config(config).get_current_head()
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ApplicationMetadata:
|
|
environment: str
|
|
build_commit: str | None
|
|
build_version: str | None
|
|
expected_migration_head: str | None
|
|
|
|
|
|
APPLICATION_METADATA = ApplicationMetadata(
|
|
environment=settings.app_env,
|
|
build_commit=_clean_build_value(settings.minerops_build_commit),
|
|
build_version=_clean_build_value(settings.minerops_build_version),
|
|
expected_migration_head=_expected_migration_head(),
|
|
)
|