Files
onGuard24/onguard24/vaultcheck.py

19 lines
581 B
Python
Raw Normal View History

import httpx
async def ping(addr: str, token: str) -> tuple[bool, str | None]:
if not addr or not token:
return False, "vault addr or token empty"
base = addr.rstrip("/")
try:
async with httpx.AsyncClient(timeout=5.0, verify=True) as client:
r = await client.get(
f"{base}/v1/sys/health",
headers={"X-Vault-Token": token},
)
except Exception as e:
return False, str(e)
if r.status_code in (200, 429, 503, 501):
return True, None
return False, f"http {r.status_code}"