"""Inventar der App-Secrets und -Zertifikate (nur Metadaten, KEINE Werte). Liest graph/applications.json und graph/servicePrincipals.json, schreibt secrets_inventory.json. Der Restore (restore/secrets_restore.py) nutzt das Inventar als Gegenprobe.""" import json, os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import m365_auth as auth def main(argv=None): p = auth.make_parser("Inventory of app secrets and certificates (metadata only, no values)") args = p.parse_args(argv) out = [] for source, _ in (("applications", "application"), ("servicePrincipals", "servicePrincipal")): for a in json.load(open(f"{args.out}/graph/{source}.json")): for key, kind in (("passwordCredentials", "Secret"), ("keyCredentials", "Certificate/Key")): for c in a.get(key) or []: out.append({"source": source, "app": a.get("displayName"), "appId": a.get("appId"), "objectId": a.get("id"), "kind": kind, "display_name": c.get("displayName"), "keyId": c.get("keyId"), "start": c.get("startDateTime"), "expires": c.get("endDateTime"), "usage": c.get("usage"), "key_type": c.get("type")}) auth.write_json(args.out + "/secrets_inventory.json", out) print(len(out), "entries;", sum(1 for o in out if o["source"] == "applications"), "on applications") return 0 if __name__ == "__main__": sys.exit(main())