f853f43b67
gates / gates (push) Successful in 24s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""Nextcloud FILES through the front door (WebDAV as the seeded user) — the household's own route."""
|
|
import secrets
|
|
|
|
|
|
def put(w, sub, t, name, body):
|
|
rc, code, out = w.app_curl(sub, f"/remote.php/dav/files/{t['uid']}/{name}", "-u", f"{t['uid']}:{t['pw']}",
|
|
"-H", "Content-Type: text/plain", method="PUT", data=body)
|
|
return code in ("201", "204")
|
|
|
|
|
|
def get(w, sub, t, name):
|
|
rc, code, out = w.app_curl(sub, f"/remote.php/dav/files/{t['uid']}/{name}", "-u", f"{t['uid']}:{t['pw']}")
|
|
return code, out
|
|
|
|
|
|
def seed_files(w, sub, t, n=3, say=print):
|
|
files = {}
|
|
for i in range(n):
|
|
name, body = f"felhom-seed-{i}-{secrets.token_hex(3)}.txt", "seed " + secrets.token_hex(16)
|
|
ok = put(w, sub, t, name, body)
|
|
say(f" nextcloud file PUT {name} ok={ok}")
|
|
if ok:
|
|
files[name] = body
|
|
return files
|
|
|
|
|
|
def verify_files(w, sub, t, files, say=print):
|
|
res = {}
|
|
for name, body in files.items():
|
|
code, out = get(w, sub, t, name)
|
|
res[name] = (code == "200" and out == body)
|
|
neg_code, _ = get(w, sub, t, "felhom-never-" + secrets.token_hex(4) + ".txt")
|
|
say(f" nextcloud files read back: {sum(res.values())}/{len(res)} (negative control http={neg_code})")
|
|
return res, neg_code
|