Files
riposte-marketplace/integrations/infoblox/scripts/get_network.py
T
Guillaume BOURGEOIS d5b7e38dd7 feat(infoblox): new Infoblox NIOS DNS-containment integration
Infoblox WAPI, 7 commands: add RPZ domain (DNS sinkhole/block), list/delete RPZ
records, search hosts, get networks, add A record. HTTP Basic auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:37:12 +02:00

75 lines
2.1 KiB
Python

import json, os, sys, base64, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/wapi/" + str(cfg.get("wapi_version") or "v2.12")
def _auth(cfg):
raw = str(cfg.get("username", "")) + ":" + str(cfg.get("password", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r:
raw = r.read()
try:
return json.loads(raw) if raw else {}
except Exception:
return {"result": raw.decode("utf-8", "replace")}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
network = inputs.get("network")
max_results = inputs.get("max_results")
params = {
"_max_results": int(max_results or 100),
}
if network:
params["network"] = network
resp = request("GET", "/network", cfg, params=params)
return {"networks": resp}
_run(main)