Compare commits
3 Commits
9da00ad7b9
...
14e5e102a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 14e5e102a9 | |||
| 460dfaefba | |||
| f826181704 |
@@ -0,0 +1,97 @@
|
|||||||
|
id: microsoft_defender_o365
|
||||||
|
name: Microsoft Defender for Office 365
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Microsoft Defender for Office 365 email remediation (Microsoft Graph mail APIs) — anti-phishing containment: search a mailbox for messages, read a message and its attachments, move a message to a folder, and hard-delete (purge) a phishing message. Azure AD OAuth2 client-credentials authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: search mailbox messages, get message, list attachments, list folders, move message, delete (purge) message."
|
||||||
|
category: email
|
||||||
|
|
||||||
|
# Per-instance configuration. Uses application (client-credentials) OAuth2.
|
||||||
|
# The app registration needs Graph application permission Mail.ReadWrite.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
tenant_id:
|
||||||
|
type: string
|
||||||
|
description: "Azure AD tenant ID"
|
||||||
|
client_id:
|
||||||
|
type: string
|
||||||
|
description: "App registration (client) ID"
|
||||||
|
client_secret:
|
||||||
|
type: string
|
||||||
|
description: "App registration client secret"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- tenant_id
|
||||||
|
- client_id
|
||||||
|
- client_secret
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: search_messages
|
||||||
|
name: mdo-search-messages
|
||||||
|
description: "Search a mailbox for messages by sender, subject, or free-text search."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (user principal name or ID)" }
|
||||||
|
subject: { type: string, description: "Filter by exact subject" }
|
||||||
|
from_address: { type: string, description: "Filter by sender address" }
|
||||||
|
search: { type: string, description: "Free-text $search query (KQL) over the mailbox" }
|
||||||
|
limit: { type: number, description: "Max messages (default 25)" }
|
||||||
|
required: [mailbox]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_message
|
||||||
|
name: mdo-get-message
|
||||||
|
description: "Get a single message by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (UPN or ID)" }
|
||||||
|
message_id: { type: string, description: "Message ID" }
|
||||||
|
required: [mailbox, message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_attachments
|
||||||
|
name: mdo-list-attachments
|
||||||
|
description: "List a message's attachments."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (UPN or ID)" }
|
||||||
|
message_id: { type: string, description: "Message ID" }
|
||||||
|
required: [mailbox, message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_folders
|
||||||
|
name: mdo-list-folders
|
||||||
|
description: "List the mail folders of a mailbox (to obtain destination IDs for move)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (UPN or ID)" }
|
||||||
|
required: [mailbox]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: move_message
|
||||||
|
name: mdo-move-message
|
||||||
|
description: "Move a message to another folder (e.g. to Junk Email or a quarantine folder)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (UPN or ID)" }
|
||||||
|
message_id: { type: string, description: "Message ID" }
|
||||||
|
destination_id: { type: string, description: "Destination folder ID or well-known name (e.g. junkemail, deleteditems)" }
|
||||||
|
required: [mailbox, message_id, destination_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: delete_message
|
||||||
|
name: mdo-delete-message
|
||||||
|
description: "Hard-delete (purge) a message from the mailbox."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
mailbox: { type: string, description: "Target mailbox (UPN or ID)" }
|
||||||
|
message_id: { type: string, description: "Message ID" }
|
||||||
|
required: [mailbox, message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: mdo-test-connection
|
||||||
|
description: "Verify connectivity and the app credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
|
||||||
|
graph("DELETE", "/users/" + q(mailbox) + "/messages/" + q(message_id), token)
|
||||||
|
return {"ok": True, "deleted": message_id}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
|
||||||
|
return graph("GET", "/users/" + q(mailbox) + "/messages/" + q(message_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
|
||||||
|
return graph("GET", "/users/" + q(mailbox) + "/messages/" + q(message_id) + "/attachments", token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
|
||||||
|
return graph("GET", "/users/" + q(mailbox) + "/mailFolders", token, params={"$top": 100})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
destination_id = inputs.get("destination_id")
|
||||||
|
if not destination_id:
|
||||||
|
raise Exception("destination_id is required")
|
||||||
|
|
||||||
|
return graph(
|
||||||
|
"POST",
|
||||||
|
"/users/" + q(mailbox) + "/messages/" + q(message_id) + "/move",
|
||||||
|
token,
|
||||||
|
body={"destinationId": destination_id},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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 _odata_escape(v):
|
||||||
|
return str(v).replace("'", "''")
|
||||||
|
|
||||||
|
|
||||||
|
def main(token, inputs):
|
||||||
|
mailbox = inputs.get("mailbox")
|
||||||
|
if not mailbox:
|
||||||
|
raise Exception("mailbox is required")
|
||||||
|
|
||||||
|
subject = inputs.get("subject")
|
||||||
|
from_address = inputs.get("from_address")
|
||||||
|
search = inputs.get("search")
|
||||||
|
limit = int(inputs.get("limit") or 25)
|
||||||
|
|
||||||
|
if search:
|
||||||
|
params = {"$search": '"' + search + '"', "$top": limit}
|
||||||
|
elif subject or from_address:
|
||||||
|
parts = []
|
||||||
|
if subject:
|
||||||
|
parts.append("subject eq '" + _odata_escape(subject) + "'")
|
||||||
|
if from_address:
|
||||||
|
parts.append("from/emailAddress/address eq '" + _odata_escape(from_address) + "'")
|
||||||
|
params = {"$filter": " and ".join(parts), "$top": limit}
|
||||||
|
else:
|
||||||
|
params = {"$top": limit}
|
||||||
|
|
||||||
|
return graph("GET", "/users/" + q(mailbox) + "/messages", token, params=params)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
tenant = str(cfg.get("tenant_id", ""))
|
||||||
|
url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token"
|
||||||
|
form = urllib.parse.urlencode({
|
||||||
|
"grant_type": "client_credentials",
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
"client_secret": str(cfg.get("client_secret", "")),
|
||||||
|
"scope": "https://graph.microsoft.com/.default",
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(url, data=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def graph(method, path, token, body=None, params=None):
|
||||||
|
url = GRAPH + 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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
graph("GET", "/users", token, params={"$top": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
id: mimecast
|
||||||
|
name: Mimecast
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Mimecast (Email Security API) — anti-phishing containment: list/release/reject held messages, search messages and get message info, block URLs (managed URLs), block senders, create remediation incidents, and decode rewritten URLs. HMAC-SHA1 signed authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: held-message list/release/reject, message search + info, managed URL create/list, block sender, create remediation, URL decode."
|
||||||
|
category: email
|
||||||
|
|
||||||
|
# Per-instance configuration. Requests are signed (HMAC-SHA1) with the
|
||||||
|
# application + access/secret keys.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "Mimecast API base URL (e.g. https://eu-api.mimecast.com)"
|
||||||
|
app_id:
|
||||||
|
type: string
|
||||||
|
description: "Application ID"
|
||||||
|
app_key:
|
||||||
|
type: string
|
||||||
|
description: "Application Key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
access_key:
|
||||||
|
type: string
|
||||||
|
description: "Access Key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
secret_key:
|
||||||
|
type: string
|
||||||
|
description: "Secret Key (base64)"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- app_id
|
||||||
|
- app_key
|
||||||
|
- access_key
|
||||||
|
- secret_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: list_held_messages
|
||||||
|
name: mimecast-list-held-messages
|
||||||
|
description: "List messages currently held for review."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
admin: { type: boolean, description: "List all held messages (admin view) vs. the account's own (default true)" }
|
||||||
|
limit: { type: number, description: "Max messages (default 100)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: release_held_message
|
||||||
|
name: mimecast-release-held-message
|
||||||
|
description: "Release a held message for delivery."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
message_id: { type: string, description: "Held message ID" }
|
||||||
|
required: [message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: reject_held_message
|
||||||
|
name: mimecast-reject-held-message
|
||||||
|
description: "Reject a held message."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
message_id: { type: string, description: "Held message ID" }
|
||||||
|
reason: { type: string, description: "Optional rejection reason" }
|
||||||
|
required: [message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: search_messages
|
||||||
|
name: mimecast-search-messages
|
||||||
|
description: "Search tracked messages by sender, recipient, or subject."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
from: { type: string, description: "Sender address filter" }
|
||||||
|
to: { type: string, description: "Recipient address filter" }
|
||||||
|
subject: { type: string, description: "Subject filter" }
|
||||||
|
start: { type: string, description: "ISO-8601 start time" }
|
||||||
|
end: { type: string, description: "ISO-8601 end time" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_message_info
|
||||||
|
name: mimecast-get-message-info
|
||||||
|
description: "Get delivery and processing details for a tracked message."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
message_id: { type: string, description: "Message ID" }
|
||||||
|
required: [message_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: create_managed_url
|
||||||
|
name: mimecast-create-managed-url
|
||||||
|
description: "Add a URL to the managed URL list (block or permit)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "URL to manage" }
|
||||||
|
action: { type: string, description: "block or permit (default block)" }
|
||||||
|
match_type: { type: string, description: "explicit or domain (default explicit)" }
|
||||||
|
comment: { type: string, description: "Optional comment" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_managed_urls
|
||||||
|
name: mimecast-list-managed-urls
|
||||||
|
description: "List managed URLs (block/permit list)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: block_sender
|
||||||
|
name: mimecast-block-sender
|
||||||
|
description: "Block (or permit) a sender for a recipient."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
sender: { type: string, description: "Sender address to block/permit" }
|
||||||
|
recipient: { type: string, description: "Recipient address the rule applies to" }
|
||||||
|
action: { type: string, description: "block or permit (default block)" }
|
||||||
|
required: [sender, recipient]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: create_remediation
|
||||||
|
name: mimecast-create-remediation
|
||||||
|
description: "Create a remediation incident to pull malicious messages from mailboxes."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
message_hash: { type: string, description: "File hash to remediate (provide this or message_id)" }
|
||||||
|
message_id: { type: string, description: "Message ID / internet message ID to remediate" }
|
||||||
|
reason: { type: string, description: "Reason for remediation" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: decode_url
|
||||||
|
name: mimecast-decode-url
|
||||||
|
description: "Decode a Mimecast-rewritten URL back to its original form."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "Rewritten URL to decode" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: mimecast-test-connection
|
||||||
|
description: "Verify connectivity and the signed credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
sender = inputs.get("sender")
|
||||||
|
if not sender:
|
||||||
|
raise Exception("sender is required")
|
||||||
|
recipient = inputs.get("recipient")
|
||||||
|
if not recipient:
|
||||||
|
raise Exception("recipient is required")
|
||||||
|
action = inputs.get("action")
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"sender": sender,
|
||||||
|
"to": recipient,
|
||||||
|
"action": action or "block",
|
||||||
|
}
|
||||||
|
return call("/api/managedsender/permit-or-block-sender", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
action = inputs.get("action")
|
||||||
|
match_type = inputs.get("match_type")
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"url": url,
|
||||||
|
"action": action or "block",
|
||||||
|
"matchType": match_type or "explicit",
|
||||||
|
}
|
||||||
|
comment = inputs.get("comment")
|
||||||
|
if comment:
|
||||||
|
payload["comment"] = comment
|
||||||
|
|
||||||
|
return call("/api/ttp/url/create-managed-url", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
message_hash = inputs.get("message_hash")
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_hash and not message_id:
|
||||||
|
raise Exception("message_hash or message_id is required")
|
||||||
|
|
||||||
|
payload = {}
|
||||||
|
if message_hash:
|
||||||
|
payload["hash"] = message_hash
|
||||||
|
if message_id:
|
||||||
|
payload["messageId"] = message_id
|
||||||
|
reason = inputs.get("reason")
|
||||||
|
if reason:
|
||||||
|
payload["reason"] = reason
|
||||||
|
|
||||||
|
return call("/api/ttp/remediation/create", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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 call("/api/ttp/url/decode-url", cfg, {"url": url})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
return call("/api/message-finder/get-message-info", cfg, {"id": message_id})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
admin = inputs.get("admin")
|
||||||
|
if admin is None:
|
||||||
|
admin = True
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
if limit is None:
|
||||||
|
limit = 100
|
||||||
|
payload = {
|
||||||
|
"admin": bool(admin),
|
||||||
|
"pagination": {"pageSize": int(limit)},
|
||||||
|
}
|
||||||
|
return call("/api/gateway/get-hold-message-list", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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 call("/api/ttp/url/get-all-managed-urls", cfg, None)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
payload = {"id": message_id}
|
||||||
|
reason = inputs.get("reason")
|
||||||
|
if reason:
|
||||||
|
payload["message"] = reason
|
||||||
|
return call("/api/gateway/hold-reject", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
message_id = inputs.get("message_id")
|
||||||
|
if not message_id:
|
||||||
|
raise Exception("message_id is required")
|
||||||
|
return call("/api/gateway/hold-release", cfg, {"id": message_id})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
from_addr = inputs.get("from")
|
||||||
|
to_addr = inputs.get("to")
|
||||||
|
subject = inputs.get("subject")
|
||||||
|
start = inputs.get("start")
|
||||||
|
end = inputs.get("end")
|
||||||
|
|
||||||
|
payload = {}
|
||||||
|
if from_addr:
|
||||||
|
payload["from"] = from_addr
|
||||||
|
if to_addr:
|
||||||
|
payload["to"] = to_addr
|
||||||
|
if subject:
|
||||||
|
payload["subject"] = subject
|
||||||
|
if start:
|
||||||
|
payload["start"] = start
|
||||||
|
if end:
|
||||||
|
payload["end"] = end
|
||||||
|
|
||||||
|
return call("/api/message-finder/search", cfg, payload)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import json, os, sys, hmac, hashlib, base64, uuid, datetime
|
||||||
|
import 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 call(uri, cfg, data_payload=None):
|
||||||
|
base_url = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
app_id = str(cfg.get("app_id", ""))
|
||||||
|
app_key = str(cfg.get("app_key", ""))
|
||||||
|
access_key = str(cfg.get("access_key", ""))
|
||||||
|
secret_key = str(cfg.get("secret_key", ""))
|
||||||
|
|
||||||
|
request_id = str(uuid.uuid4())
|
||||||
|
hdr_date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC")
|
||||||
|
to_sign = hdr_date + ":" + request_id + ":" + uri + ":" + app_key
|
||||||
|
sig = base64.b64encode(
|
||||||
|
hmac.new(base64.b64decode(secret_key), to_sign.encode("utf-8"), hashlib.sha1).digest()
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "MC " + access_key + ":" + sig,
|
||||||
|
"x-mc-app-id": app_id,
|
||||||
|
"x-mc-date": hdr_date,
|
||||||
|
"x-mc-req-id": request_id,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
body = {"data": [data_payload] if data_payload is not None else []}
|
||||||
|
req = urllib.request.Request(base_url + uri, data=json.dumps(body).encode("utf-8"), headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
resp = json.loads(raw) if raw else {}
|
||||||
|
fails = resp.get("fail") if isinstance(resp, dict) else None
|
||||||
|
if fails:
|
||||||
|
# Mimecast returns errors in the 'fail' array even on HTTP 200
|
||||||
|
raise Exception("Mimecast error: " + json.dumps(fails))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
call("/api/account/get-account", cfg, None)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
id: proofpoint_tap
|
||||||
|
name: Proofpoint TAP
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Proofpoint Targeted Attack Protection (TAP SIEM API v2) — email threat detection and forensics: pull blocked/delivered message and click events, get threat/campaign forensics, list campaigns, decode URL Defense links, and read top clickers. Service-principal (HTTP Basic) authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: SIEM events (all/messages/clicks), forensics, campaign get/list, URL decode, top clickers."
|
||||||
|
category: email
|
||||||
|
|
||||||
|
# Per-instance configuration. The service principal + secret authenticate via
|
||||||
|
# HTTP Basic against the TAP API.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: "TAP API base URL"
|
||||||
|
default: "https://tap-api-v2.proofpoint.com"
|
||||||
|
service_principal:
|
||||||
|
type: string
|
||||||
|
description: "TAP service principal"
|
||||||
|
secret:
|
||||||
|
type: string
|
||||||
|
description: "TAP secret"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- service_principal
|
||||||
|
- secret
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: get_events
|
||||||
|
name: proofpoint-get-events
|
||||||
|
description: "Get all TAP events (messages and clicks, blocked and permitted) in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
since_seconds: { type: number, description: "Look-back window in seconds, 60-3600 (default 3600)" }
|
||||||
|
interval: { type: string, description: "Optional ISO-8601 interval (overrides since_seconds), e.g. 2024-01-01T00:00:00Z/2024-01-01T01:00:00Z" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: messages_blocked
|
||||||
|
name: proofpoint-messages-blocked
|
||||||
|
description: "Get messages blocked in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
since_seconds: { type: number, description: "Look-back window in seconds, 60-3600 (default 3600)" }
|
||||||
|
interval: { type: string, description: "Optional ISO-8601 interval" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: messages_delivered
|
||||||
|
name: proofpoint-messages-delivered
|
||||||
|
description: "Get messages delivered (with threats) in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
since_seconds: { type: number, description: "Look-back window in seconds, 60-3600 (default 3600)" }
|
||||||
|
interval: { type: string, description: "Optional ISO-8601 interval" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: clicks_blocked
|
||||||
|
name: proofpoint-clicks-blocked
|
||||||
|
description: "Get clicks to malicious URLs blocked in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
since_seconds: { type: number, description: "Look-back window in seconds, 60-3600 (default 3600)" }
|
||||||
|
interval: { type: string, description: "Optional ISO-8601 interval" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: clicks_permitted
|
||||||
|
name: proofpoint-clicks-permitted
|
||||||
|
description: "Get clicks to malicious URLs permitted in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
since_seconds: { type: number, description: "Look-back window in seconds, 60-3600 (default 3600)" }
|
||||||
|
interval: { type: string, description: "Optional ISO-8601 interval" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_forensics
|
||||||
|
name: proofpoint-get-forensics
|
||||||
|
description: "Get forensic evidence for a threat or campaign."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
threat_id: { type: string, description: "Threat ID (provide this or campaign_id)" }
|
||||||
|
campaign_id: { type: string, description: "Campaign ID (provide this or threat_id)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_campaign
|
||||||
|
name: proofpoint-get-campaign
|
||||||
|
description: "Get details for a single campaign."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
campaign_id: { type: string, description: "Campaign ID" }
|
||||||
|
required: [campaign_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_campaigns
|
||||||
|
name: proofpoint-list-campaigns
|
||||||
|
description: "List campaign IDs active in a time window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
interval: { type: string, description: "ISO-8601 interval (e.g. 2024-01-01T00:00:00Z/2024-01-02T00:00:00Z)" }
|
||||||
|
size: { type: number, description: "Page size (default 100)" }
|
||||||
|
page: { type: number, description: "Page number (default 1)" }
|
||||||
|
required: [interval]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: url_decode
|
||||||
|
name: proofpoint-url-decode
|
||||||
|
description: "Decode Proofpoint URL Defense rewritten URLs back to their original form."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
urls: { type: string, description: "Comma-separated rewritten URLs to decode" }
|
||||||
|
required: [urls]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: top_clickers
|
||||||
|
name: proofpoint-top-clickers
|
||||||
|
description: "Get the users who clicked the most malicious URLs in a window."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
window: { type: number, description: "Look-back window in days: 14, 30, or 90 (default 30)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: proofpoint-test-connection
|
||||||
|
description: "Verify connectivity and credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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 _time_params(inputs):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if interval:
|
||||||
|
return {"format": "json", "interval": interval}
|
||||||
|
since_seconds = inputs.get("since_seconds")
|
||||||
|
try:
|
||||||
|
since = int(since_seconds) if since_seconds not in (None, "") else 3600
|
||||||
|
except Exception:
|
||||||
|
since = 3600
|
||||||
|
since = max(60, min(3600, since))
|
||||||
|
return {"format": "json", "sinceSeconds": since}
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
return request("GET", "/siem/clicks/blocked", cfg, params=_time_params(inputs))
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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 _time_params(inputs):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if interval:
|
||||||
|
return {"format": "json", "interval": interval}
|
||||||
|
since_seconds = inputs.get("since_seconds")
|
||||||
|
try:
|
||||||
|
since = int(since_seconds) if since_seconds not in (None, "") else 3600
|
||||||
|
except Exception:
|
||||||
|
since = 3600
|
||||||
|
since = max(60, min(3600, since))
|
||||||
|
return {"format": "json", "sinceSeconds": since}
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
return request("GET", "/siem/clicks/permitted", cfg, params=_time_params(inputs))
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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):
|
||||||
|
campaign_id = inputs.get("campaign_id")
|
||||||
|
if not campaign_id:
|
||||||
|
raise Exception("campaign_id is required")
|
||||||
|
path = "/campaign/" + urllib.parse.quote(str(campaign_id), safe="")
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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 _time_params(inputs):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if interval:
|
||||||
|
return {"format": "json", "interval": interval}
|
||||||
|
since_seconds = inputs.get("since_seconds")
|
||||||
|
try:
|
||||||
|
since = int(since_seconds) if since_seconds not in (None, "") else 3600
|
||||||
|
except Exception:
|
||||||
|
since = 3600
|
||||||
|
since = max(60, min(3600, since))
|
||||||
|
return {"format": "json", "sinceSeconds": since}
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
return request("GET", "/siem/all", cfg, params=_time_params(inputs))
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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):
|
||||||
|
threat_id = inputs.get("threat_id")
|
||||||
|
campaign_id = inputs.get("campaign_id")
|
||||||
|
if not threat_id and not campaign_id:
|
||||||
|
raise Exception("threat_id or campaign_id is required")
|
||||||
|
if threat_id:
|
||||||
|
params = {"threatId": threat_id}
|
||||||
|
else:
|
||||||
|
params = {"campaignId": campaign_id}
|
||||||
|
return request("GET", "/forensics", cfg, params=params)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if not interval:
|
||||||
|
raise Exception("interval is required")
|
||||||
|
size = inputs.get("size")
|
||||||
|
page = inputs.get("page")
|
||||||
|
try:
|
||||||
|
size = int(size) if size not in (None, "") else 100
|
||||||
|
except Exception:
|
||||||
|
size = 100
|
||||||
|
try:
|
||||||
|
page = int(page) if page not in (None, "") else 1
|
||||||
|
except Exception:
|
||||||
|
page = 1
|
||||||
|
params = {"interval": interval, "size": size, "page": page}
|
||||||
|
return request("GET", "/campaign/ids", cfg, params=params)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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 _time_params(inputs):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if interval:
|
||||||
|
return {"format": "json", "interval": interval}
|
||||||
|
since_seconds = inputs.get("since_seconds")
|
||||||
|
try:
|
||||||
|
since = int(since_seconds) if since_seconds not in (None, "") else 3600
|
||||||
|
except Exception:
|
||||||
|
since = 3600
|
||||||
|
since = max(60, min(3600, since))
|
||||||
|
return {"format": "json", "sinceSeconds": since}
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
return request("GET", "/siem/messages/blocked", cfg, params=_time_params(inputs))
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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 _time_params(inputs):
|
||||||
|
interval = inputs.get("interval")
|
||||||
|
if interval:
|
||||||
|
return {"format": "json", "interval": interval}
|
||||||
|
since_seconds = inputs.get("since_seconds")
|
||||||
|
try:
|
||||||
|
since = int(since_seconds) if since_seconds not in (None, "") else 3600
|
||||||
|
except Exception:
|
||||||
|
since = 3600
|
||||||
|
since = max(60, min(3600, since))
|
||||||
|
return {"format": "json", "sinceSeconds": since}
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
return request("GET", "/siem/messages/delivered", cfg, params=_time_params(inputs))
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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", "/siem/all", cfg, params={"format": "json", "sinceSeconds": 3600})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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):
|
||||||
|
window = inputs.get("window")
|
||||||
|
try:
|
||||||
|
window = int(window) if window not in (None, "") else 30
|
||||||
|
except Exception:
|
||||||
|
window = 30
|
||||||
|
return request("GET", "/people/top-clickers", cfg, params={"window": window})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import json, os, sys, base64, 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("url") or "https://tap-api-v2.proofpoint.com")).rstrip("/") + "/v2"
|
||||||
|
|
||||||
|
|
||||||
|
def _auth_header(cfg):
|
||||||
|
raw = str(cfg.get("service_principal", "")) + ":" + str(cfg.get("secret", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth_header(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) 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):
|
||||||
|
urls = inputs.get("urls")
|
||||||
|
if not urls:
|
||||||
|
raise Exception("urls is required")
|
||||||
|
urls_list = [u.strip() for u in str(urls).split(",") if u.strip()]
|
||||||
|
if not urls_list:
|
||||||
|
raise Exception("urls is required")
|
||||||
|
return request("POST", "/url/decode", cfg, body={"urls": urls_list})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user