← Lesson
Secrets and Security
Joeven
Run
Reset
Python loads on first run
import re SECRETS = {"STRIPE_KEY": "sk-live-DEMO-not-real"} SECRET_RE = re.compile(r"sk-[A-Za-z0-9-]+") def redact(text): return SECRET_RE.sub("[REDACTED_KEY]", text) def get_invoice(auth_tenant, args): requested = args.get("tenant") if requested and requested != auth_tenant: return {"ok": False, "code": "PERMISSION_DENIED"} raw_error = "upstream 500, key=" + SECRETS["STRIPE_KEY"] return {"ok": True, "tenant": auth_tenant, "note": redact(raw_error)} print(get_invoice("acme", {"tenant": "acme", "id": 1})) print(get_invoice("acme", {"tenant": "other", "id": 1})) print("prompt would see:", redact("use sk-live-DEMO-not-real please"))
Run to execute this in your browser. Nothing is sent to a server.