feat(cloud): Alembic, license token v2 with modules, plan presets, module editor
Platform v2 step 1.7 (APPS_PLATFORM D-3, D-20, D-21, D-22, §5.2).
- Alembic replaces create_all + _run_migrations. 0001_cloud_baseline is
exactly the v1 production schema (incl. the dead menu_hours_en/_gr), checked
against a frozen fixture; schema.py refuses an unstamped v1 DB, so prod is
stamped once at cutover (DEPLOYMENT_GUIDE Part 6)
- 0002_v2_licensing: sites.modules (JSON), sites.module_catalog(_at),
plan_presets; existing sites get every module v1 had (KDS unlimited); the
same map is seeded as preset "Everything (v1 sites)"; dead columns dropped
- license token v: 2 with a normalized `modules` map
- heartbeat v2: request {version, local_ip, module_catalog} (catalogue stored
per site); response {license_token, latest_version, waiter_domain,
site_numeric_id} - the unsigned v1 license fields are gone
- sites API: create with a preset, PUT /{id}/modules (validated),
POST /{id}/apply-preset/{preset}; /api/presets CRUD
- sysadmin panel: Licensed modules card per site (built from the reported
catalogue, fallback list), preset picker on register, Presets page
- .dockerignore: local *.db, .env and tests no longer baked into the image
- tests (new): baseline = v1, unstamped refused, stamp+upgrade of a v1 DB,
drift, token v2 shape/signature, module edits, presets; CL-2/CL-7 rules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,11 @@ it keeps running until `expires_at` (+ its grace), however long it is without
|
||||
internet, and nobody can extend it by editing the stored copy.
|
||||
|
||||
Format: <base64url(payload JSON)>.<base64url(Ed25519 signature of the first part)>
|
||||
Payload: { v: 1, site_id, active, locked, lock_reason, expires_at, issued_at }
|
||||
Payload v2 (platform v2, D-3, D-21; v2 sites accept nothing else):
|
||||
{ v: 2, site_id, active, locked, lock_reason, expires_at, issued_at,
|
||||
modules: { <module key>: { limits?: {name: int|null}, exp?: ISO } } }
|
||||
`modules` comes from sites.modules (sysadmin panel). A module missing from the map is
|
||||
not licensed (the site's free tier still applies). null limit = unlimited.
|
||||
issued_at = the cloud's clock — the site uses it as a floor against clock rollback.
|
||||
|
||||
Key: LICENSE_SIGNING_KEY in the cloud .env (base64 raw Ed25519 private key,
|
||||
@@ -46,18 +50,34 @@ def _iso(dt: datetime) -> str:
|
||||
return (dt if dt.tzinfo else dt.replace(tzinfo=timezone.utc)).astimezone(timezone.utc).isoformat()
|
||||
|
||||
|
||||
def normalize_modules(raw: dict) -> dict:
|
||||
"""Clean a module map for the token: only `limits` and `exp`, limits int or None."""
|
||||
out = {}
|
||||
for key, spec in (raw or {}).items():
|
||||
spec = spec or {}
|
||||
entry = {}
|
||||
limits = {k: (None if v is None else int(v)) for k, v in (spec.get("limits") or {}).items()}
|
||||
if limits:
|
||||
entry["limits"] = limits
|
||||
if spec.get("exp"):
|
||||
entry["exp"] = spec["exp"]
|
||||
out[key] = entry
|
||||
return out
|
||||
|
||||
|
||||
def issue_license_token(site, now: datetime) -> str | None:
|
||||
key = _signing_key()
|
||||
if key is None:
|
||||
return None
|
||||
payload = {
|
||||
"v": 1,
|
||||
"v": 2,
|
||||
"site_id": site.site_id,
|
||||
"active": bool(site.is_active),
|
||||
"locked": bool(site.is_locked),
|
||||
"lock_reason": site.lock_reason,
|
||||
"expires_at": _iso(site.license_expires_at),
|
||||
"issued_at": _iso(now),
|
||||
"modules": normalize_modules(site.modules or {}),
|
||||
}
|
||||
body = _b64url(json.dumps(payload, separators=(",", ":"), sort_keys=True).encode())
|
||||
return f"{body}.{_b64url(key.sign(body.encode()))}"
|
||||
|
||||
Reference in New Issue
Block a user