feat(signalsciences): new Signal Sciences (Fastly NGWAF) integration

Signal Sciences API v0, 5 commands: list sites, get suspicious IPs, list events,
add IP to list (block). API-token auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-07-12 15:44:30 +02:00
parent 771c90ef0d
commit 3c282e8e53
6 changed files with 373 additions and 0 deletions
@@ -0,0 +1,70 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://dashboard.signalsciences.net/api/v0"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _corp(cfg):
return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="")
def request(method, path, cfg, body=None, params=None):
url = BASE + 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 = {
"x-api-user": str(cfg.get("email", "")),
"x-api-token": str(cfg.get("api_token", "")),
"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) 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)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
site_name = inputs.get("site_name")
if not site_name:
raise Exception("site_name is required")
list_id = inputs.get("list_id")
if not list_id:
raise Exception("list_id is required")
ip = inputs.get("ip")
if not ip:
raise Exception("ip is required")
return request(
"PATCH",
_corp(cfg) + "/sites/" + q(site_name) + "/lists/" + q(list_id),
cfg,
body={"entries": {"additions": [ip], "deletions": []}},
)
_run(main)
@@ -0,0 +1,59 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://dashboard.signalsciences.net/api/v0"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _corp(cfg):
return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="")
def request(method, path, cfg, body=None, params=None):
url = BASE + 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 = {
"x-api-user": str(cfg.get("email", "")),
"x-api-token": str(cfg.get("api_token", "")),
"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) 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)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
site_name = inputs.get("site_name")
if not site_name:
raise Exception("site_name is required")
return request("GET", _corp(cfg) + "/sites/" + q(site_name) + "/suspiciousIPs", cfg)
_run(main)
@@ -0,0 +1,65 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://dashboard.signalsciences.net/api/v0"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _corp(cfg):
return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="")
def request(method, path, cfg, body=None, params=None):
url = BASE + 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 = {
"x-api-user": str(cfg.get("email", "")),
"x-api-token": str(cfg.get("api_token", "")),
"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) 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)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
site_name = inputs.get("site_name")
if not site_name:
raise Exception("site_name is required")
limit = inputs.get("limit")
return request(
"GET",
_corp(cfg) + "/sites/" + q(site_name) + "/events",
cfg,
params={"limit": int(limit or 50)},
)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://dashboard.signalsciences.net/api/v0"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _corp(cfg):
return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="")
def request(method, path, cfg, body=None, params=None):
url = BASE + 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 = {
"x-api-user": str(cfg.get("email", "")),
"x-api-token": str(cfg.get("api_token", "")),
"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) 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 request("GET", _corp(cfg) + "/sites", cfg)
_run(main)
@@ -0,0 +1,54 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://dashboard.signalsciences.net/api/v0"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _corp(cfg):
return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="")
def request(method, path, cfg, body=None, params=None):
url = BASE + 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 = {
"x-api-user": str(cfg.get("email", "")),
"x-api-token": str(cfg.get("api_token", "")),
"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) 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):
request("GET", _corp(cfg) + "/sites", cfg)
return {"ok": True}
_run(main)