net-kingdom/sso-mfa/k8s/privacyidea/keycape-scope-probe.py
tegwick 54a47dd810
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Record verified enrollment assurance release and automate provider contract tests
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a092fe-13b1-7f12-ac74-7d258af4d79c
2026-09-13 17:03:44 +02:00

25 lines
1.3 KiB
Python

"""Provider-local idempotent setup of an inert realm-visibility probe; emits no key."""
import contextlib,io,json,logging
SERIAL="KCFACTORSCOPE01"
DESCRIPTION="KeyCape realm visibility probe; keep disabled and unassigned"
result={"success":False}
with contextlib.redirect_stdout(io.StringIO()),contextlib.redirect_stderr(io.StringIO()):
try:
logging.disable(logging.CRITICAL)
from privacyidea.app import create_app
from privacyidea.lib.token import get_tokens,init_token
from privacyidea.lib.realm import get_realms
app=create_app(config_name="production",silent=True)
with app.app_context():
if "coulomb" not in get_realms():raise ValueError()
tokens=get_tokens(serial=SERIAL)
if not tokens:
token=init_token({"serial":SERIAL,"type":"hotp","genkey":1,"realm":"coulomb","description":DESCRIPTION})
token.token.active=False;token.token.save()
tokens=get_tokens(serial=SERIAL)
if len(tokens)!=1:raise ValueError()
data=tokens[0].token.get_vars()
if data["description"]!=DESCRIPTION or data["active"] or data["user_id"] or data["realms"]!=["coulomb"]:raise ValueError()
result={"success":True,"serial":SERIAL,"realm":"coulomb","disabled":True,"unassigned":True}
except Exception as e:result["failure_type"]=type(e).__name__
print(json.dumps(result));raise SystemExit(0 if result["success"] else 1)