From 9be28a2ff750a9696d1c201c36cdc113ec121bf5 Mon Sep 17 00:00:00 2001 From: Guillaume BOURGEOIS Date: Sun, 12 Jul 2026 00:42:02 +0200 Subject: [PATCH] feat(triage): new Hatching Triage sandbox integration Triage API v0, 7 commands: submit file (multipart _json+file) / URL, get sample, get report overview, list samples, search. Bearer-token auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) --- integrations/triage/manifest.yaml | 85 +++++++++++++++++++ integrations/triage/scripts/get_report.py | 79 +++++++++++++++++ integrations/triage/scripts/get_sample.py | 79 +++++++++++++++++ integrations/triage/scripts/list_samples.py | 76 +++++++++++++++++ integrations/triage/scripts/search.py | 79 +++++++++++++++++ integrations/triage/scripts/submit_file.py | 82 ++++++++++++++++++ integrations/triage/scripts/submit_url.py | 78 +++++++++++++++++ .../triage/scripts/test_connection.py | 76 +++++++++++++++++ 8 files changed, 634 insertions(+) create mode 100644 integrations/triage/manifest.yaml create mode 100644 integrations/triage/scripts/get_report.py create mode 100644 integrations/triage/scripts/get_sample.py create mode 100644 integrations/triage/scripts/list_samples.py create mode 100644 integrations/triage/scripts/search.py create mode 100644 integrations/triage/scripts/submit_file.py create mode 100644 integrations/triage/scripts/submit_url.py create mode 100644 integrations/triage/scripts/test_connection.py diff --git a/integrations/triage/manifest.yaml b/integrations/triage/manifest.yaml new file mode 100644 index 0000000..bbb2b4b --- /dev/null +++ b/integrations/triage/manifest.yaml @@ -0,0 +1,85 @@ +id: triage +name: Hatching Triage +version: 1.0.0 +description: "Hatching Triage (tria.ge API v0) — dynamic malware analysis: submit files and URLs, read sample status and analysis overview, list samples, and search. Bearer-token authentication; stdlib-only, no extra Python dependencies." +changelog: "1.0.0 — Initial release: submit file/URL, get sample, get report overview, list samples, search." +category: enrichment + +# Per-instance configuration. The API key is sent as 'Authorization: Bearer '. +config_schema: + properties: + base_url: + type: string + description: "Triage API base URL" + default: "https://tria.ge" + api_token: + type: string + description: "Triage API key" + x-soar-sensitive: true + required: + - api_token + +commands: + - id: submit_file + name: triage-submit-file + description: "Submit a file (base64) for analysis." + inputs_schema: + properties: + file_name: { type: string, description: "File name" } + content_base64: { type: string, description: "File content, base64-encoded" } + required: [file_name, content_base64] + outputs_schema: { properties: {} } + - id: submit_url + name: triage-submit-url + description: "Submit a URL for analysis." + inputs_schema: + properties: + url: { type: string, description: "URL to detonate" } + required: [url] + outputs_schema: { properties: {} } + - id: get_sample + name: triage-get-sample + description: "Get a sample's status and metadata." + risk: read + inputs_schema: + properties: + sample_id: { type: string, description: "Sample ID" } + required: [sample_id] + outputs_schema: { properties: {} } + - id: get_report + name: triage-get-report + description: "Get a sample's analysis overview (verdict and behavior summary)." + risk: read + inputs_schema: + properties: + sample_id: { type: string, description: "Sample ID" } + required: [sample_id] + outputs_schema: { properties: {} } + - id: list_samples + name: triage-list-samples + description: "List recent samples." + risk: read + inputs_schema: + properties: + limit: { type: number, description: "Max samples (default 20)" } + required: [] + outputs_schema: { properties: {} } + - id: search + name: triage-search + description: "Search samples with a Triage search query." + risk: read + inputs_schema: + properties: + query: { type: string, description: "Triage search query (e.g. family:emotet)" } + limit: { type: number, description: "Max results (default 20)" } + required: [query] + outputs_schema: { properties: {} } + + - id: test_connection + name: triage-test-connection + description: "Verify connectivity and the API key (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/triage/scripts/get_report.py b/integrations/triage/scripts/get_report.py new file mode 100644 index 0000000..8bd5094 --- /dev/null +++ b/integrations/triage/scripts/get_report.py @@ -0,0 +1,79 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + sample_id = inputs.get("sample_id") + if not sample_id: + raise Exception("sample_id is required") + q = lambda v: urllib.parse.quote(str(v), safe="") + return request("GET", "/api/v0/samples/" + q(sample_id) + "/overview.json", cfg) + + +_run(main) diff --git a/integrations/triage/scripts/get_sample.py b/integrations/triage/scripts/get_sample.py new file mode 100644 index 0000000..ad35d27 --- /dev/null +++ b/integrations/triage/scripts/get_sample.py @@ -0,0 +1,79 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + sample_id = inputs.get("sample_id") + if not sample_id: + raise Exception("sample_id is required") + q = lambda v: urllib.parse.quote(str(v), safe="") + return request("GET", "/api/v0/samples/" + q(sample_id), cfg) + + +_run(main) diff --git a/integrations/triage/scripts/list_samples.py b/integrations/triage/scripts/list_samples.py new file mode 100644 index 0000000..19f08df --- /dev/null +++ b/integrations/triage/scripts/list_samples.py @@ -0,0 +1,76 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + limit = inputs.get("limit") + return request("GET", "/api/v0/samples", cfg, params={"subset": "owned", "limit": int(limit or 20)}) + + +_run(main) diff --git a/integrations/triage/scripts/search.py b/integrations/triage/scripts/search.py new file mode 100644 index 0000000..7d08436 --- /dev/null +++ b/integrations/triage/scripts/search.py @@ -0,0 +1,79 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + query = inputs.get("query") + if not query: + raise Exception("query is required") + limit = inputs.get("limit") + return request("GET", "/api/v0/search", cfg, params={"query": query, "limit": int(limit or 20)}) + + +_run(main) diff --git a/integrations/triage/scripts/submit_file.py b/integrations/triage/scripts/submit_file.py new file mode 100644 index 0000000..0415c39 --- /dev/null +++ b/integrations/triage/scripts/submit_file.py @@ -0,0 +1,82 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + file_name = inputs.get("file_name") + content_base64 = inputs.get("content_base64") + if not file_name: + raise Exception("file_name is required") + if not content_base64: + raise Exception("content_base64 is required") + file_bytes = base64.b64decode(content_base64) + return submit_file_multipart(cfg, file_name, file_bytes, {"kind": "file", "interactive": False}) + + +_run(main) diff --git a/integrations/triage/scripts/submit_url.py b/integrations/triage/scripts/submit_url.py new file mode 100644 index 0000000..1e28676 --- /dev/null +++ b/integrations/triage/scripts/submit_url.py @@ -0,0 +1,78 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + url = inputs.get("url") + if not url: + raise Exception("url is required") + return request("POST", "/api/v0/samples", cfg, body={"kind": "url", "url": url, "interactive": False}) + + +_run(main) diff --git a/integrations/triage/scripts/test_connection.py b/integrations/triage/scripts/test_connection.py new file mode 100644 index 0000000..1f7f9e1 --- /dev/null +++ b/integrations/triage/scripts/test_connection.py @@ -0,0 +1,76 @@ +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") or "https://tria.ge")).rstrip("/") + + +def _headers(cfg, extra=None): + h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))} + if extra: + h.update(extra) + return h + + +def request(method, path, cfg, body=None, 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) + data = None + extra = {} + if body is not None: + data = json.dumps(body).encode("utf-8") + extra["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_file_multipart(cfg, file_name, file_bytes, json_meta): + # Triage sample submission: multipart with a '_json' text part and a 'file' part. + boundary = "----riposte" + uuid.uuid4().hex + parts = [] + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8")) + parts.append(("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8")) + parts.append(file_bytes) + parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8")) + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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): + request("GET", "/api/v0/samples", cfg, params={"subset": "owned", "limit": 1}) + return {"ok": True} + + +_run(main)