File size: 1,221 Bytes
507714c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # SPDX-License-Identifier: MIT - Copyright (c) 2026 Novaeon
"""Minimaler REST-Client fuer Flowable OSS (nur stdlib)."""
import json, base64, urllib.request, urllib.error
BASE = "http://localhost:18080/flowable-rest"
class Client:
def __init__(self, user, password):
self.auth = "Basic " + base64.b64encode(f"{user}:{password}".encode()).decode()
self.user = user
def call(self, method, path, body=None):
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(BASE + path, data=data, method=method,
headers={"Authorization": self.auth, "Content-Type": "application/json"})
try:
with urllib.request.urlopen(req, timeout=30) as r:
raw = r.read().decode()
return r.status, (json.loads(raw) if raw else None)
except urllib.error.HTTPError as e:
raw = e.read().decode()
try: return e.code, json.loads(raw)
except Exception: return e.code, raw
def vars_list(d):
return [{"name": k, "type": "string" if isinstance(v, str) else ("boolean" if isinstance(v, bool) else "integer"), "value": v} for k, v in d.items()]
|