Files
Guillaume BOURGEOIS 771c90ef0d feat(imperva): new Imperva Cloud WAF integration
Cloud Application Security API v1, 5 commands: list sites, get site status,
block/whitelist IPs (site ACL). API-ID/key auth, stdlib-only.

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

43 lines
1.3 KiB
Python

import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://my.imperva.com/api/prov/v1"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def post(path, cfg, fields=None):
body = {"api_id": str(cfg.get("api_id", "")), "api_key": str(cfg.get("api_key", ""))}
if fields:
body.update({k: v for k, v in fields.items() if v not in (None, "")})
data = urllib.parse.urlencode(body).encode("utf-8")
req = urllib.request.Request(BASE + path, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
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):
return post("/sites/list", cfg)
_run(main)