49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""Create the fixture directory on the old (Stalwart 0.15) server via its REST API."""
|
|
import base64
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
API = "http://old.test:8080"
|
|
AUTH = "Basic " + base64.b64encode(b"admin:adminpass").decode()
|
|
|
|
alice_hash, carol_hash = sys.argv[1], sys.argv[2]
|
|
|
|
|
|
def call(method, path, body=None):
|
|
req = urllib.request.Request(
|
|
API + path,
|
|
method=method,
|
|
data=json.dumps(body).encode() if body is not None else None,
|
|
headers={"Content-Type": "application/json", "Authorization": AUTH},
|
|
)
|
|
with urllib.request.urlopen(req) as r:
|
|
out = json.load(r)
|
|
if isinstance(out, dict) and "error" in out:
|
|
raise SystemExit(f"{method} {path}: {out}")
|
|
print(method, path, "->", out)
|
|
return out
|
|
|
|
|
|
def principal(**kw):
|
|
p = {
|
|
"quota": 0, "description": "", "secrets": [], "emails": [], "urls": [], "memberOf": [],
|
|
"roles": [], "lists": [], "members": [], "enabledPermissions": [], "disabledPermissions": [],
|
|
"externalMembers": [],
|
|
}
|
|
p.update(kw)
|
|
return call("POST", "/api/principal", p)
|
|
|
|
|
|
principal(type="domain", name="b4l.test")
|
|
principal(type="domain", name="poy.test")
|
|
principal(type="individual", name="alice", description="Alice Example", secrets=[alice_hash],
|
|
emails=["alice@b4l.test", "a.lias@poy.test"], quota=2 * 1024 ** 3, roles=["user"])
|
|
# plaintext secret: Stalwart accepts unhashed secrets
|
|
principal(type="individual", name="bob@b4l.test", secrets=["bobpass"], emails=["bob@b4l.test"], roles=["user"])
|
|
principal(type="individual", name="carol", secrets=[carol_hash], emails=["carol@b4l.test"], roles=["user"])
|
|
# no password at all: only reachable through the master user
|
|
principal(type="individual", name="dave", emails=["dave@poy.test"], roles=["user"])
|
|
principal(type="list", name="team", emails=["team@b4l.test"], members=["alice", "bob@b4l.test"],
|
|
externalMembers=["ext@example.org"])
|