Add Arcane project status

This commit is contained in:
2026-02-07 23:24:58 +03:00
parent e590b7e38f
commit fc9ef08525
5 changed files with 94 additions and 0 deletions

27
services/arcane.py Normal file
View File

@@ -0,0 +1,27 @@
import json
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
def list_projects(base_url: str, api_key: str, env_id: int, timeout: int = 10) -> tuple[bool, str, list[dict]]:
url = f"{base_url.rstrip('/')}/api/environments/{env_id}/projects"
req = Request(url, headers={"X-Api-Key": api_key})
try:
with urlopen(req, timeout=timeout) as resp:
raw = resp.read().decode("utf-8", errors="ignore")
except HTTPError as e:
return False, f"HTTP {e.code}", []
except URLError as e:
return False, f"URL error: {e.reason}", []
except Exception as e:
return False, f"Error: {e}", []
try:
payload = json.loads(raw)
except json.JSONDecodeError:
return False, "Invalid JSON", []
if not payload.get("success"):
return False, "API returned success=false", []
return True, "OK", payload.get("data", [])