Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2475c4b56e | |||
| 3be14f2f00 | |||
| 3a4d06441c |
@@ -0,0 +1,54 @@
|
|||||||
|
id: crowdsec
|
||||||
|
name: CrowdSec CTI
|
||||||
|
version: 1.0.0
|
||||||
|
description: "CrowdSec CTI (Cyber Threat Intelligence API v2) — IP reputation from CrowdSec's collaborative community: look up an IP's reputation and behaviors, search several IPs at once, and pull the currently-firing malicious IPs. API-key authentication; stdlib-only, no extra Python dependencies. (French vendor.)"
|
||||||
|
changelog: "1.0.0 — Initial release: IP reputation, multi-IP search, fire list."
|
||||||
|
category: enrichment
|
||||||
|
|
||||||
|
# Per-instance configuration. The CTI API key is sent as the 'x-api-key' header.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
api_key:
|
||||||
|
type: string
|
||||||
|
description: "CrowdSec CTI API key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- api_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: ip_reputation
|
||||||
|
name: crowdsec-ip-reputation
|
||||||
|
description: "Get an IP's CrowdSec reputation, behaviors and background noise score."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
ip: { type: string, description: "IP address" }
|
||||||
|
required: [ip]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: search_ips
|
||||||
|
name: crowdsec-search-ips
|
||||||
|
description: "Look up several IPs in one request."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
ips: { type: string, description: "Comma-separated IP addresses" }
|
||||||
|
required: [ips]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_fire
|
||||||
|
name: crowdsec-get-fire
|
||||||
|
description: "List IPs currently flagged as actively malicious (the fire list)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
page: { type: number, description: "Page number (default 1)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: crowdsec-test-connection
|
||||||
|
description: "Verify the API key (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://cti.api.crowdsec.net/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, 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)
|
||||||
|
req = urllib.request.Request(url, headers={"x-api-key": str(cfg.get("api_key", "")), "Accept": "application/json"}, method="GET")
|
||||||
|
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):
|
||||||
|
page = inputs.get("page")
|
||||||
|
page = int(page) if page not in (None, "") else 1
|
||||||
|
return request("/fire", cfg, params={"page": page})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://cti.api.crowdsec.net/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, 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)
|
||||||
|
req = urllib.request.Request(url, headers={"x-api-key": str(cfg.get("api_key", "")), "Accept": "application/json"}, method="GET")
|
||||||
|
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):
|
||||||
|
ip = inputs.get("ip")
|
||||||
|
if not ip:
|
||||||
|
raise Exception("ip is required")
|
||||||
|
return request("/smoke/" + q(ip), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://cti.api.crowdsec.net/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, 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)
|
||||||
|
req = urllib.request.Request(url, headers={"x-api-key": str(cfg.get("api_key", "")), "Accept": "application/json"}, method="GET")
|
||||||
|
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):
|
||||||
|
ips = inputs.get("ips")
|
||||||
|
if not ips:
|
||||||
|
raise Exception("ips is required")
|
||||||
|
return request("/smoke/search", cfg, params={"ips": ips})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://cti.api.crowdsec.net/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, 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)
|
||||||
|
req = urllib.request.Request(url, headers={"x-api-key": str(cfg.get("api_key", "")), "Accept": "application/json"}, method="GET")
|
||||||
|
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):
|
||||||
|
request("/smoke/1.1.1.1", cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
id: stormshield
|
||||||
|
name: Stormshield Network Security
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Stormshield Network Security (SNS API) — firewall containment: authenticate, add or remove an IP from a block host-group object, and run a monitor query. Session-based authentication; stdlib-only, no extra Python dependencies. (French vendor.)"
|
||||||
|
changelog: "1.0.0 — Initial release: add/remove block-group member, list host objects, monitor query."
|
||||||
|
category: network
|
||||||
|
|
||||||
|
# Per-instance configuration. Each command logs in (POST /api/auth/login) and
|
||||||
|
# reuses the returned session token for the request.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "SNS appliance URL (e.g. https://sns.example.com)"
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
description: "Admin username"
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
description: "Admin password"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
insecure:
|
||||||
|
type: boolean
|
||||||
|
description: "Trust any TLS certificate (not secure)"
|
||||||
|
default: false
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- username
|
||||||
|
- password
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: add_block_group_member
|
||||||
|
name: stormshield-add-block-group-member
|
||||||
|
description: "Add an IP/host object to a block host-group (referenced by a filter rule)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
group: { type: string, description: "Host-group object name (e.g. RIPOSTE_BLOCK)" }
|
||||||
|
host: { type: string, description: "Host object name or IP to add" }
|
||||||
|
required: [group, host]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: remove_block_group_member
|
||||||
|
name: stormshield-remove-block-group-member
|
||||||
|
description: "Remove a host from a block host-group."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
group: { type: string, description: "Host-group object name" }
|
||||||
|
host: { type: string, description: "Host object name or IP to remove" }
|
||||||
|
required: [group, host]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_hosts
|
||||||
|
name: stormshield-list-hosts
|
||||||
|
description: "List host objects."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: monitor_query
|
||||||
|
name: stormshield-monitor-query
|
||||||
|
description: "Run a monitor command (e.g. MONITOR HOST) and return its result."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
command: { type: string, description: "SNS monitor command (e.g. 'MONITOR HOST')" }
|
||||||
|
required: [command]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: stormshield-test-connection
|
||||||
|
description: "Verify connectivity and credentials by logging in (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -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)
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
id: wallix_bastion
|
||||||
|
name: WALLIX Bastion
|
||||||
|
version: 1.0.0
|
||||||
|
description: "WALLIX Bastion (PAM REST API) — privileged access visibility: list devices, accounts and authorizations, and list/read sessions. API-key authentication; stdlib-only, no extra Python dependencies. (French vendor.)"
|
||||||
|
changelog: "1.0.0 — Initial release: list devices/accounts/authorizations, list/get sessions."
|
||||||
|
category: identity
|
||||||
|
|
||||||
|
# Per-instance configuration. Auth uses the 'X-Auth-User' and 'X-Auth-Key' headers.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "Bastion URL (e.g. https://bastion.example.com)"
|
||||||
|
api_user:
|
||||||
|
type: string
|
||||||
|
description: "API user name"
|
||||||
|
api_key:
|
||||||
|
type: string
|
||||||
|
description: "API key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
insecure:
|
||||||
|
type: boolean
|
||||||
|
description: "Trust any TLS certificate (not secure)"
|
||||||
|
default: false
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- api_user
|
||||||
|
- api_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: list_devices
|
||||||
|
name: wallix-list-devices
|
||||||
|
description: "List devices."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max devices (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_accounts
|
||||||
|
name: wallix-list-accounts
|
||||||
|
description: "List accounts."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max accounts (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_authorizations
|
||||||
|
name: wallix-list-authorizations
|
||||||
|
description: "List authorizations."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_sessions
|
||||||
|
name: wallix-list-sessions
|
||||||
|
description: "List sessions (optionally filter by status)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
status: { type: string, description: "Status filter (e.g. current, closed)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_session
|
||||||
|
name: wallix-get-session
|
||||||
|
description: "Get a single session by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
session_id: { type: string, description: "Session ID" }
|
||||||
|
required: [session_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: wallix-test-connection
|
||||||
|
description: "Verify connectivity and credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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):
|
||||||
|
session_id = inputs.get("session_id")
|
||||||
|
if not session_id:
|
||||||
|
raise Exception("session_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
return request("GET", "/sessions/" + q(session_id), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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):
|
||||||
|
limit = inputs.get("limit") or 50
|
||||||
|
return request("GET", "/accounts", cfg, params={"limit": int(limit)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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", "/authorizations", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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):
|
||||||
|
limit = inputs.get("limit") or 50
|
||||||
|
return request("GET", "/devices", cfg, params={"limit": int(limit)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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):
|
||||||
|
status = inputs.get("status")
|
||||||
|
return request("GET", "/sessions", cfg, params={"status": status})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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 request(method, path, cfg, params=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {
|
||||||
|
"X-Auth-User": str(cfg.get("api_user", "")),
|
||||||
|
"X-Auth-Key": str(cfg.get("api_key", "")),
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) 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", "/devices", cfg, params={"limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user