gates / gates (push) Successful in 5s
New optional enum first_visit | email | none (default first_visit). Set on rallly and outline (email: a sign-in link) and on bentopdf, homepage, privatebin, onlyoffice, glance, metube (none; the last two are family-gated, so the page says the family sign-in is the login). Gate login-kind with decoys. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""check-login-kind.py — `app_info.login_kind` is one of the three values the controller knows.
|
|
|
|
python3 scripts/check-login-kind.py # every app
|
|
python3 scripts/check-login-kind.py --root DIR # another checkout (the decoy harness)
|
|
|
|
`app_info.login_kind` (controller >= 0.320.0, `02-controller-module-map.md` „The app page") tells the app page how
|
|
the household signs in when the box holds no login: `first_visit` (the default — leave the key out), `email` (the app
|
|
mails a sign-in link) or `none` (no sign-in). It is an ENUM, not copy: the sentence is the controller's, so the key
|
|
never appears in the English `i18n:` block (copy-i18n refuses it there as an unknown app_info key).
|
|
|
|
A value the controller does not know reads as `first_visit` there — safe, but the author meant something else. This
|
|
gate refuses it, so the typo is found at push time instead of on a box.
|
|
|
|
STANDARD LIBRARY ONLY (the CI runner has no PyYAML). The value is read by indentation: `login_kind:` at two spaces
|
|
directly under the top-level `app_info:` — a comment, the English block (six spaces) and any other mapping are never
|
|
read as the fact.
|
|
"""
|
|
import io
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
KNOWN = ("first_visit", "email", "none")
|
|
KEY = re.compile(r"^ login_kind:\s*(.*)$")
|
|
|
|
|
|
def strip_comment(line):
|
|
out, q = [], None
|
|
for c in line:
|
|
if q:
|
|
if c == q:
|
|
q = None
|
|
elif c in "'\"":
|
|
q = c
|
|
elif c == "#":
|
|
break
|
|
out.append(c)
|
|
return "".join(out).rstrip()
|
|
|
|
|
|
def login_kinds(path):
|
|
"""Every `login_kind:` value directly under top-level app_info (normally zero or one)."""
|
|
vals, in_ai = [], False
|
|
with io.open(path, encoding="utf-8") as f:
|
|
for raw in f:
|
|
line = strip_comment(raw.rstrip("\n"))
|
|
if not line.strip():
|
|
continue
|
|
if not line.startswith(" "):
|
|
in_ai = line.startswith("app_info:")
|
|
continue
|
|
if in_ai:
|
|
m = KEY.match(line)
|
|
if m:
|
|
v = m.group(1).strip()
|
|
if len(v) >= 2 and v[0] == v[-1] and v[0] in "'\"":
|
|
v = v[1:-1]
|
|
vals.append(v)
|
|
return vals
|
|
|
|
|
|
def main(argv):
|
|
root = ROOT
|
|
for a in argv:
|
|
if a.startswith("--root="):
|
|
root = a.split("=", 1)[1]
|
|
if "--root" in argv:
|
|
root = argv[argv.index("--root") + 1]
|
|
tdir = os.path.join(root, "templates")
|
|
if not os.path.isdir(tdir):
|
|
print("check-login-kind: no templates/ under %s — nothing to judge (a failure, never a pass)" % root)
|
|
return 3
|
|
bad, seen = [], 0
|
|
for app in sorted(os.listdir(tdir)):
|
|
p = os.path.join(tdir, app, ".felhom.yml")
|
|
if not os.path.isfile(p):
|
|
continue
|
|
vals = login_kinds(p)
|
|
seen += len(vals)
|
|
if len(vals) > 1:
|
|
bad.append("%s: app_info.login_kind appears %d times" % (app, len(vals)))
|
|
for v in vals:
|
|
if v not in KNOWN:
|
|
bad.append("%s: app_info.login_kind %r is not one of %s" % (app, v, ", ".join(KNOWN)))
|
|
if bad:
|
|
print("check-login-kind: %d FAILURE(S)" % len(bad))
|
|
for b in bad:
|
|
print(" - " + b)
|
|
return 1
|
|
print("check-login-kind gate OK — %d login_kind key(s), each one of %s" % (seen, ", ".join(KNOWN)))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|