feat(stormshield): new Stormshield SNS firewall integration (French vendor)

Stormshield SNS API, 5 commands: add/remove block host-group member (containment),
list hosts, monitor query. Session (login) auth, stdlib-only. py_compile clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-07-12 16:07:38 +02:00
parent 3be14f2f00
commit 2475c4b56e
6 changed files with 517 additions and 0 deletions
@@ -0,0 +1,82 @@
import json, os, sys, ssl, base64, http.cookiejar
import 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 _b64(s):
return base64.b64encode(str(s).encode("utf-8")).decode("ascii")
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("base_url", "")).rstrip("/")
ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=ctx) if ctx else urllib.request.HTTPSHandler(),
)
def login(self):
form = urllib.parse.urlencode({"uid": _b64(self.cfg.get("username", "")), "pswd": _b64(self.cfg.get("password", ""))}).encode("utf-8")
req = urllib.request.Request(self.base + "/api/auth/login", data=form,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with self.opener.open(req, timeout=60) as r:
return r.read().decode("utf-8", "replace")
def command(self, cmd):
form = urllib.parse.urlencode({"cmd": cmd}).encode("utf-8")
req = urllib.request.Request(self.base + "/api/command", data=form,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with self.opener.open(req, timeout=60) as r:
return r.read().decode("utf-8", "replace")
def logout(self):
try:
req = urllib.request.Request(self.base + "/api/auth/logout", data=b"", method="POST")
self.opener.open(req, timeout=30).read()
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
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(client, inputs):
client.command("SYSTEM PROPERTY")
return {"ok": True}
_run(main)