extend_pins: wyby-Buchungs-PINs auf tageweise Gueltigkeit erweitern

- glutz_api.py: vendorierter JSON-RPC-Client (aus glutz-eaccess-api)
- extend_pins.py: Dry-Run-Standard, --apply, --only-code fuer Schreibtests
  * wyby-Benutzer via Label-Muster '<Name> <6 Ziffern>'
  * Fenster aus Code-Gueltigkeit abgeleitet (Buchung +/- Puffer, Default 15 min)
  * idempotent: tageweise/persoenliche/abgelaufene Codes werden uebersprungen
- deploy/: systemd oneshot + Timer 05:40..23:40 stuendlich, deploy.sh
- README.md, .env.example ergaenzt
This commit is contained in:
2026-10-22 21:45:29 +02:00
parent 8623e8e745
commit 6ab00fcb9f
7 changed files with 365 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""Glutz eAccess Cloud — minimaler JSON-RPC-Client (nur Stdlib).
Übernommen aus ../glutz-eaccess-api/glutz_api.py (auf Client-Funktionen
reduziert), damit dieses Deployment selbst-contained ist.
* Endpunkt: https://<instanz>.eaccess.glutz.com/rpc
* Auth: HTTP Basic (GLUTZ_USER / GLUTZ_PASS aus .env)
* Lesen: eAccess.getModel params=[Collection, Filter, Fields]
* Schreiben: eAccess.setModel params=[Collection, DataObject]
"""
from __future__ import annotations
import base64
import json
import os
import sys
import urllib.error
import urllib.request
from pathlib import Path
RPC_ID = 4711
def load_env(path: Path | None = None) -> None:
"""Lädt KEY=VALUE aus .env (neben diesem Script), ohne bestehende ENV zu überschreiben."""
env_file = path or Path(__file__).resolve().parent / ".env"
if not env_file.is_file():
return
for line in env_file.read_text().splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, _, value = line.partition("=")
key, value = key.strip(), value.strip().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
def rpc(method: str, params: list) -> dict:
"""Einzelner JSON-RPC-Aufruf; bei Fehler sys.exit mit Meldung."""
host = os.environ["GLUTZ_HOST"].rstrip("/")
user = os.environ["GLUTZ_USER"]
password = os.environ["GLUTZ_PASS"]
token = base64.b64encode(f"{user}:{password}".encode()).decode()
payload = json.dumps(
{"jsonrpc": "2.0", "id": RPC_ID, "method": method, "params": params}
).encode()
req = urllib.request.Request(
f"{host}/rpc",
data=payload,
headers={
"Content-Type": "application/json",
"Authorization": f"Basic {token}",
},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
data = json.load(resp)
except urllib.error.HTTPError as err:
sys.exit(f"HTTP {err.code}: {err.read().decode(errors='replace')[:400]}")
except urllib.error.URLError as err:
sys.exit(f"Netzwerkfehler bei {method}: {err}")
if "error" in data:
sys.exit(f"RPC-Fehler bei {method}: {json.dumps(data['error'])}")
return data.get("result", {})