feat(onelogin): new OneLogin identity-containment integration
OneLogin API v1/v2, 6 commands: list/get users, lock user, logout user (revoke sessions), list events. OAuth2 client-credentials auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
id: onelogin
|
||||||
|
name: OneLogin
|
||||||
|
version: 1.0.0
|
||||||
|
description: "OneLogin (API v1/v2) — identity containment: list and read users, lock a user, log a user out of all sessions, and read events. OAuth2 client-credentials authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: list/get users, lock user, logout user, list events."
|
||||||
|
category: identity
|
||||||
|
|
||||||
|
# Per-instance configuration. Client credentials are exchanged for a bearer token.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "OneLogin API base URL (region-specific)"
|
||||||
|
default: "https://api.us.onelogin.com"
|
||||||
|
client_id:
|
||||||
|
type: string
|
||||||
|
description: "API client ID"
|
||||||
|
client_secret:
|
||||||
|
type: string
|
||||||
|
description: "API client secret"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- client_id
|
||||||
|
- client_secret
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: list_users
|
||||||
|
name: onelogin-list-users
|
||||||
|
description: "List users (optionally filter by email)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
email: { type: string, description: "Optional email filter" }
|
||||||
|
limit: { type: number, description: "Max users (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_user
|
||||||
|
name: onelogin-get-user
|
||||||
|
description: "Get a single user by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
user_id: { type: string, description: "User ID" }
|
||||||
|
required: [user_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: lock_user
|
||||||
|
name: onelogin-lock-user
|
||||||
|
description: "Lock a user account (containment)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
user_id: { type: string, description: "User ID" }
|
||||||
|
locked_minutes: { type: number, description: "Lock duration in minutes (0 = indefinite, default 0)" }
|
||||||
|
required: [user_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: logout_user
|
||||||
|
name: onelogin-logout-user
|
||||||
|
description: "Log a user out of all active sessions."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
user_id: { type: string, description: "User ID" }
|
||||||
|
required: [user_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_events
|
||||||
|
name: onelogin-list-events
|
||||||
|
description: "List events (optionally filter by user)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
user_id: { type: string, description: "Optional user ID filter" }
|
||||||
|
event_type_id: { type: string, description: "Optional event type ID filter" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: onelogin-test-connection
|
||||||
|
description: "Verify the credentials via the token exchange (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
user_id = inputs.get("user_id")
|
||||||
|
if not user_id:
|
||||||
|
raise Exception("user_id is required")
|
||||||
|
return request("GET", "/api/2/users/" + q(user_id), cfg, token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
user_id = inputs.get("user_id")
|
||||||
|
event_type_id = inputs.get("event_type_id")
|
||||||
|
return request("GET", "/api/1/events", cfg, token, params={"user_id": user_id, "event_type_id": event_type_id})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
email = inputs.get("email")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
return request("GET", "/api/2/users", cfg, token, params={"email": email, "limit": int(limit or 50)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
user_id = inputs.get("user_id")
|
||||||
|
if not user_id:
|
||||||
|
raise Exception("user_id is required")
|
||||||
|
locked_minutes = inputs.get("locked_minutes")
|
||||||
|
return request("POST", "/api/1/users/" + q(user_id) + "/lock_user", cfg, token,
|
||||||
|
body={"locked_until": int(locked_minutes or 0)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
user_id = inputs.get("user_id")
|
||||||
|
if not user_id:
|
||||||
|
raise Exception("user_id is required")
|
||||||
|
return request("PUT", "/api/1/users/" + q(user_id) + "/logout", cfg, token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return (str(cfg.get("base_url") or "https://api.us.onelogin.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
auth = "client_id:" + str(cfg.get("client_id", "")) + ", client_secret:" + str(cfg.get("client_secret", ""))
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/auth/oauth2/v2/token", data=body,
|
||||||
|
headers={"Authorization": auth, "Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
at = tok.get("access_token")
|
||||||
|
if not at:
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return at
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, token, 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": "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=60) 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(cfg, 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(cfg, token, inputs):
|
||||||
|
request("GET", "/api/2/users", cfg, token, params={"limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user