ariadne/ariadne/services/wolf_gatekeeper.py
2026-05-21 15:53:17 -03:00

42 lines
1.4 KiB
Python

from __future__ import annotations
from typing import Any
import httpx
from ..settings import settings
class WolfGatekeeperService:
"""Manage temporary Moonlight firewall unlocks through the titan-24 agent."""
def enabled(self) -> bool:
return bool(settings.wolf_gatekeeper_url)
def _request(self, method: str, path: str, payload: dict[str, Any] | None = None) -> dict[str, Any]:
if not self.enabled():
raise RuntimeError("wolf gatekeeper not configured")
url = f"{settings.wolf_gatekeeper_url.rstrip('/')}/{path.lstrip('/')}"
with httpx.Client(timeout=settings.wolf_gatekeeper_timeout_sec) as client:
resp = client.request(method, url, json=payload)
resp.raise_for_status()
data = resp.json()
if not isinstance(data, dict):
raise RuntimeError("unexpected wolf gatekeeper response")
return data
def status(self) -> dict[str, Any]:
return self._request("GET", "/status")
def unlock(self, ip: str, ttl_seconds: int, actor: str, target_user: str | None = None) -> dict[str, Any]:
payload = {"ip": ip, "ttl_seconds": ttl_seconds, "actor": actor}
if target_user:
payload["target_user"] = target_user
return self._request("POST", "/unlock", payload)
def revoke(self, ip: str) -> dict[str, Any]:
return self._request("POST", "/revoke", {"ip": ip})
wolf_gatekeeper = WolfGatekeeperService()