import json, os, sys, urllib.error, urllib.request def _cfg(): return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) def main(): cfg = _cfg() base = str(cfg.get("base_url") or "").rstrip("/") if not base: raise Exception("base_url is not configured") req = urllib.request.Request( base + "/api/ingest/clients", headers={ "Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("token") or ""), "User-Agent": "Riposte-SOAR/sextant", }, method="GET", ) with urllib.request.urlopen(req, timeout=30) as r: result = json.loads(r.read() or b"{}") clients = result.get("clients", []) # The unpaired ones are surfaced separately rather than left to be spotted in # a list: they are the whole reason somebody runs this command twice. unpaired = [c.get("code") for c in clients if not c.get("soar_client_id")] print(json.dumps({"clients": clients, "unpaired": unpaired})) try: main() except urllib.error.HTTPError as e: print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) sys.exit(1) except Exception as e: print(json.dumps({"error": str(e)})) sys.exit(1)