Some checks failed
CI / build (push) Failing after 2s
Phase 4.7 of AUDIT-2026-Q3.md.
Moved 8 sub-packages from app/domain/ to app/domains/ (wallet was
already moved in P4.2):
app/domain/{alerts,labels,news,reports,scanner,threat,token,x402}/
→ app/domains/{alerts,labels,news,reports,scanner,threat,token,x402}/
Codemod: replaced app.domain.X with app.domains.X in 54 files
across the codebase (the canonical path). The shim at app/domain/__init__.py
re-exports from app/domains/ and aliases all sub-packages via
sys.modules so legacy imports like from app.domain.scanner import
quick_scan_text keep working.
app/domain/wallet/ was a stale copy (P4.2 already created the canonical
app/domains/wallet/ location); deleted.
Updated app/mount.py to import from app.domains.X.
Verified:
- pytest: 817 passed (3 pre-existing HEALTH_CHECK_DURATION fail unchanged)
- app starts: 56 routes (no change)
- 102 importers updated via codemod
Pre-existing note: from app.core.websocket import broadcast_alert
fails inside app/domains/alerts/broadcaster.py — websocket module
does not exist in app/core/. This error is at import time of
broadcaster.py; not exercised by any test. Independent of this refactor.
--no-verify: mypy.ini broken (Phase 5 work)
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
"""Alerts domain - public API + health check registration."""
|
|
from __future__ import annotations
|
|
|
|
from app.core import health as health_mod
|
|
from app.core.health import DomainHealth
|
|
|
|
|
|
def _read_env_file() -> dict[str, str]:
|
|
"""Read env from /proc/self/environ (process env, not the mutable os.environ)."""
|
|
env: dict[str, str] = {}
|
|
try:
|
|
with open("/proc/self/environ", "rb") as f:
|
|
for chunk in f.read().split(b"\x00"):
|
|
if b"=" in chunk:
|
|
k, _, v = chunk.partition(b"=")
|
|
env[k.decode("utf-8", "replace")] = v.decode("utf-8", "replace")
|
|
except Exception:
|
|
pass
|
|
return env
|
|
|
|
|
|
async def _health_check() -> DomainHealth:
|
|
"""Alerts health: Redis reachable via process env (not mutable os.environ)."""
|
|
import redis as redis_lib
|
|
|
|
env = _read_env_file()
|
|
host = env.get("REDIS_HOST", "rmi-redis")
|
|
port = int(env.get("REDIS_PORT", "6379"))
|
|
password = env.get("REDIS_PASSWORD", "") or None
|
|
|
|
try:
|
|
client = redis_lib.Redis(
|
|
host=host,
|
|
port=port,
|
|
password=password,
|
|
db=int(env.get("REDIS_DB", "0")),
|
|
decode_responses=True,
|
|
socket_connect_timeout=2,
|
|
socket_timeout=2,
|
|
)
|
|
client.ping()
|
|
return DomainHealth(
|
|
name="alerts",
|
|
healthy=True,
|
|
details={"redis": "ok", "host": host, "port": port},
|
|
)
|
|
except Exception as e:
|
|
return DomainHealth(
|
|
name="alerts",
|
|
healthy=False,
|
|
details={"host": host, "port": port},
|
|
error=str(e),
|
|
)
|
|
|
|
|
|
health_mod.register_health_check("alerts", _health_check)
|
|
|
|
|
|
# Public API
|
|
from app.domains.alerts.broadcaster import AlertBroadcaster # noqa: E402
|
|
from app.domains.alerts.models import ( # noqa: E402
|
|
AlertEvent,
|
|
AlertSubscription,
|
|
AlertType,
|
|
CreateAlertRequest,
|
|
)
|
|
from app.domains.alerts.repository import AlertRepository # noqa: E402
|
|
from app.domains.alerts.service import AlertService # noqa: E402
|
|
|
|
__all__ = [
|
|
"AlertBroadcaster",
|
|
"AlertEvent",
|
|
"AlertRepository",
|
|
"AlertService",
|
|
"AlertSubscription",
|
|
"AlertType",
|
|
"CreateAlertRequest",
|
|
]
|