feat(glimps): new GLIMPS Detect malware-analysis integration (French vendor)
GDetect API lite v2, 4 commands: submit file (multipart), get result by UUID, search by SHA-256. Token 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,66 @@
|
||||
import json, os, sys, base64, uuid, 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 _base(cfg):
|
||||
return str(cfg.get("base_url", "")).rstrip("/") + "/api/lite/v2"
|
||||
|
||||
|
||||
def _headers(cfg, extra=None):
|
||||
h = {"X-Auth-Token": str(cfg.get("api_token", "")), "Accept": "application/json"}
|
||||
if extra:
|
||||
h.update(extra)
|
||||
return h
|
||||
|
||||
|
||||
def get(path, cfg, params=None):
|
||||
url = _base(cfg) + 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=_headers(cfg), method="GET")
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def submit_multipart(path, cfg, file_field, file_name, file_bytes):
|
||||
boundary = "----riposte" + uuid.uuid4().hex
|
||||
parts = [("--" + boundary + "\r\n"
|
||||
'Content-Disposition: form-data; name="' + file_field + '"; filename="' + file_name + '"\r\n'
|
||||
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"),
|
||||
file_bytes,
|
||||
("\r\n--" + boundary + "--\r\n").encode("utf-8")]
|
||||
data = b"".join(parts)
|
||||
req = urllib.request.Request(_base(cfg) + path, data=data,
|
||||
headers=_headers(cfg, {"Content-Type": "multipart/form-data; boundary=" + boundary}), method="POST")
|
||||
with urllib.request.urlopen(req, timeout=180) 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):
|
||||
get("/status", cfg)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
_run(main)
|
||||
Reference in New Issue
Block a user