"""SharePoint-Tenant-Einstellungen über die Admin-Site (REST, nur GET) und Graph (admin/sharepoint/settings). Das Token für die Admin-Site wird mit dem Zertifikat aus m365_auth geholt; der Host ergibt sich aus M365_TENANT_NAME (https://-admin.sharepoint.com). Ausgabe nach spo_tenant/.""" import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import m365_auth as auth from m365_auth import write_json ENDPOINTS = [ ("web", "/_api/web"), ("site", "/_api/site"), ("tenant_SPO", "/_api/SPO.Tenant"), ("tenant_TenantAdmin", "/_api/Microsoft.Online.SharePoint.TenantAdministration.Tenant"), ("tenant_Internal", "/_api/SPOInternalUseOnly.Tenant"), ("tenant_sites", "/_api/SPO.Tenant/GetSitePropertiesFromSharePointByFilters"), ("tenantSettings", "/_api/SP.TenantSettings.Current"), ("web_currentuser", "/_api/web/currentuser"), ("web_features", "/_api/web/features"), ("web_lists", "/_api/web/lists"), ("site_features", "/_api/site/features"), ("web_roleassignments", "/_api/web/roleassignments"), ("siteusers", "/_api/web/siteusers"), ("sitegroups", "/_api/web/sitegroups"), ("webtemplates", "/_api/web/GetAvailableWebTemplates(1033)"), ("tenantAppCatalog", "/_api/SP.TenantAdmin.Tenant"), ("hubsites", "/_api/hubsites"), ("themes", "/_api/SP.Utilities.ThemeManager/GetTenantThemingOptions"), ("siteproperties_odata", "/_api/Microsoft.Online.SharePoint.TenantAdministration.SiteProperties"), ("storage_quota", "/_api/StorageQuotas")] def sp_get(admin_host, path, timeout=60): """GET gegen die SharePoint-REST-Schnittstelle der Admin-Site, mit App-only-Token.""" import requests return requests.get(admin_host + path, timeout=timeout, headers={ "Authorization": "Bearer " + auth.token(admin_host + "/.default"), "Accept": "application/json;odata=nometadata"}) def main(argv=None): p = auth.make_parser("Read SharePoint tenant settings via the admin site (read-only)") args = p.parse_args(argv) root = os.path.join(args.out, "spo_tenant"); os.makedirs(root, exist_ok=True) admin_host = f"https://{auth.tenant_prefix()}-admin.sharepoint.com" ok, not_possible = {}, {} for name, path in ENDPOINTS: try: r = sp_get(admin_host, path) except Exception as e: not_possible[name] = {"url": path, "status": None, "message": str(e)[:200]}; continue if r.status_code == 200: try: write_json(os.path.join(root, name + ".json"), r.json()); ok[name] = 1 except Exception: not_possible[name] = {"url": path, "status": 200, "message": "no JSON answer"} else: not_possible[name] = {"url": path, "status": r.status_code, "message": r.text[:200]} print(name, r.status_code) # Graph: SharePoint-Tenant-Einstellungen r = auth.g("GET", "https://graph.microsoft.com/v1.0/admin/sharepoint/settings") if r.status_code == 200: write_json(os.path.join(root, "graph_admin_sharepoint_settings.json"), r.json()); ok["graph_settings"] = 1 else: not_possible["graph_admin_sharepoint_settings"] = {"status": r.status_code, "message": r.text[:200]} write_json(os.path.join(root, "not_possible.json"), not_possible) write_json(os.path.join(root, "_summary.json"), {"ok": ok, "not_possible": not_possible}) auth.log(args.out, f"done {len(ok)} ok, {len(not_possible)} not possible", "spo") return 0 if __name__ == "__main__": sys.exit(main())