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:
@@ -0,0 +1,96 @@
|
||||
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):
|
||||
group = inputs.get("group")
|
||||
host = inputs.get("host")
|
||||
if not group:
|
||||
raise Exception("group is required")
|
||||
if not host:
|
||||
raise Exception("host is required")
|
||||
|
||||
add_result = client.command("CONFIG OBJECT GROUP ADDTO group=" + group + " node=" + host)
|
||||
activate_result = client.command("CONFIG OBJECT ACTIVATE")
|
||||
|
||||
return {
|
||||
"group": group,
|
||||
"host": host,
|
||||
"add_result": add_result,
|
||||
"activate_result": activate_result,
|
||||
}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -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):
|
||||
r = client.command("CONFIG OBJECT LIST type=host")
|
||||
return {"result": r}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,86 @@
|
||||
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):
|
||||
command = inputs.get("command")
|
||||
if not command:
|
||||
raise Exception("command is required")
|
||||
|
||||
r = client.command(command)
|
||||
return {"command": command, "result": r}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,96 @@
|
||||
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):
|
||||
group = inputs.get("group")
|
||||
host = inputs.get("host")
|
||||
if not group:
|
||||
raise Exception("group is required")
|
||||
if not host:
|
||||
raise Exception("host is required")
|
||||
|
||||
remove_result = client.command("CONFIG OBJECT GROUP REMOVEFROM group=" + group + " node=" + host)
|
||||
activate_result = client.command("CONFIG OBJECT ACTIVATE")
|
||||
|
||||
return {
|
||||
"group": group,
|
||||
"host": host,
|
||||
"remove_result": remove_result,
|
||||
"activate_result": activate_result,
|
||||
}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user