auditex 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. auditex/__init__.py +23 -0
  2. auditex/__main__.py +4 -0
  3. auditex/answer_checks.py +292 -0
  4. auditex/answer_digest.py +407 -0
  5. auditex/answer_frames.json +40 -0
  6. auditex/assessment_review.py +355 -0
  7. auditex/assessment_sources.py +16 -0
  8. auditex/auth_runtime.py +218 -0
  9. auditex/bootstrap.py +340 -0
  10. auditex/ce_plus.py +684 -0
  11. auditex/cli.py +1599 -0
  12. auditex/command_builders.py +256 -0
  13. auditex/command_runner.py +386 -0
  14. auditex/compare.py +834 -0
  15. auditex/demo.py +476 -0
  16. auditex/evidence_db.py +8 -0
  17. auditex/explorer.py +1237 -0
  18. auditex/explorer_assets/LICENSE-lucide.txt +43 -0
  19. auditex/explorer_assets/explorer.css +509 -0
  20. auditex/explorer_assets/explorer.html +64 -0
  21. auditex/explorer_assets/explorer.js +990 -0
  22. auditex/explorer_assets/fonts/Barlow-400-latin-ext.woff2 +0 -0
  23. auditex/explorer_assets/fonts/Barlow-400-latin-ext.woff2.range +1 -0
  24. auditex/explorer_assets/fonts/Barlow-400-latin.woff2 +0 -0
  25. auditex/explorer_assets/fonts/Barlow-400-latin.woff2.range +1 -0
  26. auditex/explorer_assets/fonts/Barlow-600-latin-ext.woff2 +0 -0
  27. auditex/explorer_assets/fonts/Barlow-600-latin-ext.woff2.range +1 -0
  28. auditex/explorer_assets/fonts/Barlow-600-latin.woff2 +0 -0
  29. auditex/explorer_assets/fonts/Barlow-600-latin.woff2.range +1 -0
  30. auditex/explorer_assets/fonts/BarlowCondensed-600-latin-ext.woff2 +0 -0
  31. auditex/explorer_assets/fonts/BarlowCondensed-600-latin-ext.woff2.range +1 -0
  32. auditex/explorer_assets/fonts/BarlowCondensed-600-latin.woff2 +0 -0
  33. auditex/explorer_assets/fonts/BarlowCondensed-600-latin.woff2.range +1 -0
  34. auditex/explorer_assets/fonts/OFL.txt +93 -0
  35. auditex/exporters.py +95 -0
  36. auditex/external_assessments.py +319 -0
  37. auditex/features.py +15 -0
  38. auditex/gate.py +825 -0
  39. auditex/google_workspace/__init__.py +17 -0
  40. auditex/google_workspace/auth.py +403 -0
  41. auditex/google_workspace/client.py +688 -0
  42. auditex/google_workspace/collectors.py +998 -0
  43. auditex/google_workspace/findings.py +2330 -0
  44. auditex/google_workspace/normalize.py +773 -0
  45. auditex/google_workspace/run.py +1219 -0
  46. auditex/guided.py +338 -0
  47. auditex/local_answer.py +1045 -0
  48. auditex/mcp_paths.py +139 -0
  49. auditex/mcp_registry.py +270 -0
  50. auditex/mcp_server.py +1443 -0
  51. auditex/notify.py +763 -0
  52. auditex/operator_flow.py +47 -0
  53. auditex/output_writers.py +211 -0
  54. auditex/reporting.py +4699 -0
  55. auditex/rule_assessment.py +493 -0
  56. auditex/rules.py +356 -0
  57. auditex/run_bundle.py +544 -0
  58. auditex/scope_postcheck.py +81 -0
  59. auditex/scuba_adapters_aad.py +398 -0
  60. auditex/scuba_adapters_defender.py +162 -0
  61. auditex/scuba_adapters_exchange.py +63 -0
  62. auditex/scuba_adapters_powerplat.py +94 -0
  63. auditex/scuba_adapters_teams.py +230 -0
  64. auditex/scuba_projection.py +2345 -0
  65. auditex/scubagear_export.py +871 -0
  66. auditex/scubagear_prune_proof.py +575 -0
  67. auditex/setup_guide.py +668 -0
  68. auditex-2.0.0.data/data/auditex/agent/agent-prompt.md +60 -0
  69. auditex-2.0.0.data/data/auditex/agent/tenant-audit-skill.json +265 -0
  70. auditex-2.0.0.data/data/auditex/assets/auditex-logo-64.png +0 -0
  71. auditex-2.0.0.data/data/auditex/assets/auditex-logo.svg +14 -0
  72. auditex-2.0.0.data/data/auditex/configs/assessment-sources.json +145 -0
  73. auditex-2.0.0.data/data/auditex/configs/ce-plus-practice.json +1463 -0
  74. auditex-2.0.0.data/data/auditex/configs/collector-definitions.json +990 -0
  75. auditex-2.0.0.data/data/auditex/configs/collector-permissions.json +460 -0
  76. auditex-2.0.0.data/data/auditex/configs/collector-presets.json +82 -0
  77. auditex-2.0.0.data/data/auditex/configs/control-mappings.json +3560 -0
  78. auditex-2.0.0.data/data/auditex/configs/explainer-baselines.json +10987 -0
  79. auditex-2.0.0.data/data/auditex/configs/explainer-template.json +1 -0
  80. auditex-2.0.0.data/data/auditex/configs/explainer-what-to-collect.json +27838 -0
  81. auditex-2.0.0.data/data/auditex/configs/finding-templates.json +1503 -0
  82. auditex-2.0.0.data/data/auditex/configs/framework-catalog.json +509 -0
  83. auditex-2.0.0.data/data/auditex/configs/os-end-of-life.json +736 -0
  84. auditex-2.0.0.data/data/auditex/configs/report-sections.json +129 -0
  85. auditex-2.0.0.data/data/auditex/configs/risky-delegated-permissions.json +767 -0
  86. auditex-2.0.0.data/data/auditex/configs/rule-packs.json +1709 -0
  87. auditex-2.0.0.data/data/auditex/configs/scuba-policy-sections.json +1151 -0
  88. auditex-2.0.0.data/data/auditex/configs/scuba-rule-precheck.json +538 -0
  89. auditex-2.0.0.data/data/auditex/configs/scuba-scope-blind.json +197 -0
  90. auditex-2.0.0.data/data/auditex/configs/scuba-value-rules.json +22013 -0
  91. auditex-2.0.0.data/data/auditex/docs/guides/admin-permission-guide.md +507 -0
  92. auditex-2.0.0.data/data/auditex/docs/guides/ai-assessment.md +159 -0
  93. auditex-2.0.0.data/data/auditex/docs/guides/customer-handoff-guide.md +159 -0
  94. auditex-2.0.0.data/data/auditex/docs/guides/external-assessments.md +96 -0
  95. auditex-2.0.0.data/data/auditex/docs/guides/install-guide.md +377 -0
  96. auditex-2.0.0.data/data/auditex/docs/guides/local-answer.md +114 -0
  97. auditex-2.0.0.data/data/auditex/docs/guides/model-development.md +40 -0
  98. auditex-2.0.0.data/data/auditex/docs/guides/product-manual.md +521 -0
  99. auditex-2.0.0.data/data/auditex/docs/guides/reader-app-permissions.md +328 -0
  100. auditex-2.0.0.data/data/auditex/docs/guides/setup-guide.md +249 -0
  101. auditex-2.0.0.data/data/auditex/docs/guides/troubleshooting.md +214 -0
  102. auditex-2.0.0.data/data/auditex/docs/index.md +42 -0
  103. auditex-2.0.0.data/data/auditex/docs/legal/third-party-notices.md +117 -0
  104. auditex-2.0.0.data/data/auditex/docs/legal/trademarks.md +19 -0
  105. auditex-2.0.0.data/data/auditex/docs/provenance/explainer-baselines.md +98 -0
  106. auditex-2.0.0.data/data/auditex/docs/provenance/provenance.csv +44 -0
  107. auditex-2.0.0.data/data/auditex/docs/provenance/provenance.md +199 -0
  108. auditex-2.0.0.data/data/auditex/docs/reference/api-call-catalog.md +334 -0
  109. auditex-2.0.0.data/data/auditex/docs/reference/framework-mappings.md +638 -0
  110. auditex-2.0.0.data/data/auditex/docs/reference/output-contract.md +1878 -0
  111. auditex-2.0.0.data/data/auditex/docs/reference/security-privacy.md +1077 -0
  112. auditex-2.0.0.data/data/auditex/examples/demo_tenant/demo_tenant.json +1074 -0
  113. auditex-2.0.0.data/data/auditex/examples/demo_tenant/demo_tenant_remediated.json +1083 -0
  114. auditex-2.0.0.data/data/auditex/examples/google_workspace_sample.json +563 -0
  115. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/admin_set_result.json +382 -0
  116. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/endpoint_posture_result.json +363 -0
  117. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_maester.json +38 -0
  118. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_monkey365.json +66 -0
  119. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/external_scubagear.json +41 -0
  120. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/identity_controls_result.json +254 -0
  121. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/known_bad_result.json +164 -0
  122. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/sample_result.json +41 -0
  123. auditex-2.0.0.data/data/auditex/examples/sample_audit_bundle/update_rings_missing_result.json +103 -0
  124. auditex-2.0.0.data/data/auditex/profiles/app-readonly-full.md +11 -0
  125. auditex-2.0.0.data/data/auditex/profiles/exchange-reader.md +11 -0
  126. auditex-2.0.0.data/data/auditex/profiles/global-reader.md +11 -0
  127. auditex-2.0.0.data/data/auditex/profiles/intune-reader.md +11 -0
  128. auditex-2.0.0.data/data/auditex/profiles/security-reader.md +11 -0
  129. auditex-2.0.0.data/data/auditex/schemas/ai_context.schema.json +30 -0
  130. auditex-2.0.0.data/data/auditex/schemas/blocker.schema.json +14 -0
  131. auditex-2.0.0.data/data/auditex/schemas/blockers.schema.json +6 -0
  132. auditex-2.0.0.data/data/auditex/schemas/bundle_hashes.schema.json +38 -0
  133. auditex-2.0.0.data/data/auditex/schemas/capability_matrix.schema.json +41 -0
  134. auditex-2.0.0.data/data/auditex/schemas/ce_plus_practice.schema.json +653 -0
  135. auditex-2.0.0.data/data/auditex/schemas/collector_result.schema.json +13 -0
  136. auditex-2.0.0.data/data/auditex/schemas/explainer.schema.json +13 -0
  137. auditex-2.0.0.data/data/auditex/schemas/finding.schema.json +277 -0
  138. auditex-2.0.0.data/data/auditex/schemas/local_answer.schema.json +133 -0
  139. auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-27.1.schema.json +288 -0
  140. auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-27.schema.json +271 -0
  141. auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-28.schema.json +453 -0
  142. auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-10-29.schema.json +1245 -0
  143. auditex-2.0.0.data/data/auditex/schemas/model_assessment-2026-11-05.schema.json +1339 -0
  144. auditex-2.0.0.data/data/auditex/schemas/model_assessment.schema.json +1387 -0
  145. auditex-2.0.0.data/data/auditex/schemas/report_pack.schema.json +41 -0
  146. auditex-2.0.0.data/data/auditex/schemas/run_manifest.schema.json +195 -0
  147. auditex-2.0.0.data/data/auditex/schemas/summary.schema.json +32 -0
  148. auditex-2.0.0.data/data/auditex/schemas/targeted_users_coverage.schema.json +29 -0
  149. auditex-2.0.0.data/data/auditex/schemas/validation.schema.json +28 -0
  150. auditex-2.0.0.data/data/auditex/skills/app-readonly-escalation/SKILL.md +26 -0
  151. auditex-2.0.0.data/data/auditex/skills/auditex-operator/SKILL.md +43 -0
  152. auditex-2.0.0.data/data/auditex/skills/evidence-pack/SKILL.md +29 -0
  153. auditex-2.0.0.dist-info/METADATA +292 -0
  154. auditex-2.0.0.dist-info/RECORD +321 -0
  155. auditex-2.0.0.dist-info/WHEEL +5 -0
  156. auditex-2.0.0.dist-info/entry_points.txt +4 -0
  157. auditex-2.0.0.dist-info/licenses/LICENSE +202 -0
  158. auditex-2.0.0.dist-info/licenses/NOTICE +46 -0
  159. auditex-2.0.0.dist-info/top_level.txt +2 -0
  160. azure_tenant_audit/__init__.py +5 -0
  161. azure_tenant_audit/__main__.py +4 -0
  162. azure_tenant_audit/adapters/__init__.py +35 -0
  163. azure_tenant_audit/adapters/base.py +34 -0
  164. azure_tenant_audit/adapters/capabilities.py +43 -0
  165. azure_tenant_audit/adapters/m365_cli.py +156 -0
  166. azure_tenant_audit/adapters/m365dsc.py +124 -0
  167. azure_tenant_audit/adapters/powershell_graph.py +655 -0
  168. azure_tenant_audit/adapters/read_guard.py +738 -0
  169. azure_tenant_audit/adapters/teams_admin_rest.py +336 -0
  170. azure_tenant_audit/ai_context.py +159 -0
  171. azure_tenant_audit/api_inventory.py +927 -0
  172. azure_tenant_audit/argument_parser.py +121 -0
  173. azure_tenant_audit/assurance.py +349 -0
  174. azure_tenant_audit/attack_graph.py +986 -0
  175. azure_tenant_audit/auth_context.py +148 -0
  176. azure_tenant_audit/auth_runtime.py +81 -0
  177. azure_tenant_audit/autopilot.py +728 -0
  178. azure_tenant_audit/baselines.py +1372 -0
  179. azure_tenant_audit/break_glass.py +499 -0
  180. azure_tenant_audit/bundle_integrity.py +467 -0
  181. azure_tenant_audit/capability_gate.py +278 -0
  182. azure_tenant_audit/catalog.py +75 -0
  183. azure_tenant_audit/certificate_auth.py +342 -0
  184. azure_tenant_audit/chunk_reader.py +167 -0
  185. azure_tenant_audit/citations.py +45 -0
  186. azure_tenant_audit/cli.py +1323 -0
  187. azure_tenant_audit/cli_guard.py +335 -0
  188. azure_tenant_audit/collection_gaps.py +584 -0
  189. azure_tenant_audit/collection_markers.py +3 -0
  190. azure_tenant_audit/collector_runner.py +342 -0
  191. azure_tenant_audit/collectors/__init__.py +75 -0
  192. azure_tenant_audit/collectors/_capability_gated.py +169 -0
  193. azure_tenant_audit/collectors/_endpoint_reads.py +371 -0
  194. azure_tenant_audit/collectors/anti_phish_admission.py +345 -0
  195. azure_tenant_audit/collectors/app_consent.py +409 -0
  196. azure_tenant_audit/collectors/app_credentials.py +392 -0
  197. azure_tenant_audit/collectors/auth_methods.py +55 -0
  198. azure_tenant_audit/collectors/base.py +564 -0
  199. azure_tenant_audit/collectors/conditional_access.py +68 -0
  200. azure_tenant_audit/collectors/consent_policy.py +192 -0
  201. azure_tenant_audit/collectors/copilot_governance.py +68 -0
  202. azure_tenant_audit/collectors/cross_tenant_access.py +187 -0
  203. azure_tenant_audit/collectors/defender.py +80 -0
  204. azure_tenant_audit/collectors/defender_cloud_apps.py +43 -0
  205. azure_tenant_audit/collectors/directory_relationships.py +93 -0
  206. azure_tenant_audit/collectors/dns_posture.py +432 -0
  207. azure_tenant_audit/collectors/domains_hybrid.py +49 -0
  208. azure_tenant_audit/collectors/ediscovery.py +435 -0
  209. azure_tenant_audit/collectors/exchange.py +70 -0
  210. azure_tenant_audit/collectors/exchange_defender_commands.py +117 -0
  211. azure_tenant_audit/collectors/exchange_policy.py +438 -0
  212. azure_tenant_audit/collectors/external_identity.py +41 -0
  213. azure_tenant_audit/collectors/identity.py +262 -0
  214. azure_tenant_audit/collectors/identity_governance.py +297 -0
  215. azure_tenant_audit/collectors/identity_protection.py +125 -0
  216. azure_tenant_audit/collectors/intune.py +105 -0
  217. azure_tenant_audit/collectors/intune_depth.py +377 -0
  218. azure_tenant_audit/collectors/licensing.py +58 -0
  219. azure_tenant_audit/collectors/mailbox_forwarding.py +534 -0
  220. azure_tenant_audit/collectors/onedrive_posture.py +122 -0
  221. azure_tenant_audit/collectors/power_bi.py +83 -0
  222. azure_tenant_audit/collectors/power_platform.py +249 -0
  223. azure_tenant_audit/collectors/purview.py +274 -0
  224. azure_tenant_audit/collectors/reports_usage.py +162 -0
  225. azure_tenant_audit/collectors/security.py +78 -0
  226. azure_tenant_audit/collectors/sentinel_xdr.py +37 -0
  227. azure_tenant_audit/collectors/service_health.py +41 -0
  228. azure_tenant_audit/collectors/sharepoint.py +52 -0
  229. azure_tenant_audit/collectors/sharepoint_access.py +358 -0
  230. azure_tenant_audit/collectors/sharepoint_admin.py +440 -0
  231. azure_tenant_audit/collectors/targeted_users_coverage.py +799 -0
  232. azure_tenant_audit/collectors/teams.py +109 -0
  233. azure_tenant_audit/collectors/teams_policy.py +170 -0
  234. azure_tenant_audit/config.py +104 -0
  235. azure_tenant_audit/contracts.py +1084 -0
  236. azure_tenant_audit/cyber_essentials.py +195 -0
  237. azure_tenant_audit/data_handling.py +236 -0
  238. azure_tenant_audit/data_minimisation.py +201 -0
  239. azure_tenant_audit/detection_coverage.py +364 -0
  240. azure_tenant_audit/diagnostics.py +153 -0
  241. azure_tenant_audit/diffing.py +655 -0
  242. azure_tenant_audit/directory_relationships.py +31 -0
  243. azure_tenant_audit/dns_lookup.py +819 -0
  244. azure_tenant_audit/effective_admins.py +602 -0
  245. azure_tenant_audit/endpoint_posture.py +558 -0
  246. azure_tenant_audit/evidence_db.py +600 -0
  247. azure_tenant_audit/evidence_gates.py +186 -0
  248. azure_tenant_audit/evidence_refs.py +409 -0
  249. azure_tenant_audit/exchange_protection.py +237 -0
  250. azure_tenant_audit/explainer/__init__.py +52 -0
  251. azure_tenant_audit/explainer/adapter.py +35 -0
  252. azure_tenant_audit/explainer/baselines.py +450 -0
  253. azure_tenant_audit/explainer/collection.py +183 -0
  254. azure_tenant_audit/explainer/generate.py +224 -0
  255. azure_tenant_audit/explainer/render.py +214 -0
  256. azure_tenant_audit/explainer/textkit.py +336 -0
  257. azure_tenant_audit/explainer/view.py +100 -0
  258. azure_tenant_audit/exposure_lookup.py +498 -0
  259. azure_tenant_audit/external_sharing.py +529 -0
  260. azure_tenant_audit/finalize.py +373 -0
  261. azure_tenant_audit/findings.py +4648 -0
  262. azure_tenant_audit/friendly_names.py +165 -0
  263. azure_tenant_audit/graph.py +1098 -0
  264. azure_tenant_audit/guarded_io.py +1304 -0
  265. azure_tenant_audit/identity_controls.py +1698 -0
  266. azure_tenant_audit/normalize.py +3376 -0
  267. azure_tenant_audit/offline_replay.py +243 -0
  268. azure_tenant_audit/os_lifecycle.py +224 -0
  269. azure_tenant_audit/output.py +1109 -0
  270. azure_tenant_audit/output_redaction.py +2871 -0
  271. azure_tenant_audit/partner_domains.py +180 -0
  272. azure_tenant_audit/perf_runtime.py +106 -0
  273. azure_tenant_audit/power_bi.py +58 -0
  274. azure_tenant_audit/power_platform.py +141 -0
  275. azure_tenant_audit/presets.py +80 -0
  276. azure_tenant_audit/private_io.py +173 -0
  277. azure_tenant_audit/privileged_roles.py +246 -0
  278. azure_tenant_audit/probe.py +743 -0
  279. azure_tenant_audit/profiles.py +257 -0
  280. azure_tenant_audit/provider_registry.py +21 -0
  281. azure_tenant_audit/provider_runtime.py +127 -0
  282. azure_tenant_audit/resources.py +220 -0
  283. azure_tenant_audit/response.py +829 -0
  284. azure_tenant_audit/rule_parameters.py +167 -0
  285. azure_tenant_audit/run.py +552 -0
  286. azure_tenant_audit/run_files.py +182 -0
  287. azure_tenant_audit/scope_catalog.py +195 -0
  288. azure_tenant_audit/scuba_assessment.py +646 -0
  289. azure_tenant_audit/scuba_precheck.py +316 -0
  290. azure_tenant_audit/scuba_scope.py +213 -0
  291. azure_tenant_audit/secret_hygiene.py +717 -0
  292. azure_tenant_audit/selection.py +31 -0
  293. azure_tenant_audit/sensitive_users.py +178 -0
  294. azure_tenant_audit/shipped_content.py +122 -0
  295. azure_tenant_audit/strict_json.py +19 -0
  296. azure_tenant_audit/tenant_identity.py +267 -0
  297. azure_tenant_audit/text_validity.py +77 -0
  298. azure_tenant_audit/utils.py +38 -0
  299. azure_tenant_audit/value_rules/__init__.py +77 -0
  300. azure_tenant_audit/value_rules/aad_authz.py +140 -0
  301. azure_tenant_audit/value_rules/aad_pilot.py +439 -0
  302. azure_tenant_audit/value_rules/aad_roles.py +182 -0
  303. azure_tenant_audit/value_rules/catalogue.py +184 -0
  304. azure_tenant_audit/value_rules/conditional_access.py +673 -0
  305. azure_tenant_audit/value_rules/defender_cascade.py +274 -0
  306. azure_tenant_audit/value_rules/defender_dlp.py +209 -0
  307. azure_tenant_audit/value_rules/defender_phish.py +360 -0
  308. azure_tenant_audit/value_rules/defender_resolution.py +486 -0
  309. azure_tenant_audit/value_rules/defender_spam.py +222 -0
  310. azure_tenant_audit/value_rules/defender_targeted_users.py +182 -0
  311. azure_tenant_audit/value_rules/dns.py +339 -0
  312. azure_tenant_audit/value_rules/exo_open.py +56 -0
  313. azure_tenant_audit/value_rules/gates.py +52 -0
  314. azure_tenant_audit/value_rules/helpers.py +312 -0
  315. azure_tenant_audit/value_rules/lookups.py +311 -0
  316. azure_tenant_audit/value_rules/power_platform.py +149 -0
  317. azure_tenant_audit/value_rules/powerbi.py +138 -0
  318. azure_tenant_audit/value_rules/record.py +162 -0
  319. azure_tenant_audit/value_rules/sharepoint.py +125 -0
  320. azure_tenant_audit/versioning.py +47 -0
  321. azure_tenant_audit/waivers.py +304 -0
auditex/__init__.py ADDED
@@ -0,0 +1,23 @@
1
+ """Auditex product wrapper for the Azure tenant audit engine."""
2
+
3
+ from azure_tenant_audit.provider_registry import register_provider
4
+
5
+
6
+ def _google_collectors():
7
+ from .google_workspace.collectors import REGISTRY
8
+
9
+ return REGISTRY
10
+
11
+
12
+ # Every product entry point imports this package, including reports and exports
13
+ # that consume existing Google bundles without running a Google collector first.
14
+ register_provider("google_workspace", _google_collectors)
15
+
16
+
17
+ def main() -> int:
18
+ from .cli import main as cli_main
19
+
20
+ return cli_main()
21
+
22
+
23
+ __all__ = ["main"]
auditex/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
@@ -0,0 +1,292 @@
1
+ """Fail-closed checks on a local model's answers, the renderer and the fixed-text fallback (DEC-113, DEC-119).
2
+
3
+ The model writes no text (DEC-119); it selects and arranges. For each digest item (``answer_digest``) it returns one
4
+ JSON object and nothing else, ``{"use": ["is-not-met", "requirement", "step-1"], "show": ["v4"]}``: ``use`` selects
5
+ sentences of the item's bank (``answer_digest.item_bank``: the fixed frames of ``answer_frames.json`` whose
6
+ preconditions hold on the item's rule facts, the baseline requirement and, for a not met item, the baseline
7
+ remediation steps), ``show`` selects values Auditex renders quoted. For the whole run it returns
8
+ ``{"summary": ["run-counts"], "highlight": [1, 2]}``: run frames whose count preconditions hold
9
+ (``answer_digest.run_bank``), their counts filled by Auditex, and the numbers of the items to list first
10
+ (``answer_digest.highlightable``). Auditex renders every word; the rules decide every verdict and the order.
11
+
12
+ Item answer checks (anything else fails and the item shows ``fallback_text``):
13
+ 1. form: one JSON object (as text, or already parsed) with exactly the keys use and show, strict JSON (a duplicate
14
+ key or a constant such as NaN fails), each a list of strings.
15
+ 2. use: at least one id (``empty``), at most the ``use`` limit of the frames file (``limit``), no id twice
16
+ (``duplicate``), each id in the item's bank. A frame or catalogue sentence id the bank does not hold for this item
17
+ fails ``precondition`` (``is-met`` on a not met item, ``step-1`` on a met one, ``mandatory`` without a catalogue
18
+ Shall); any other id fails ``unknown``.
19
+ 3. show: distinct reference ids (``v4``) of this item's values other than its check and verdict, which Auditex always
20
+ renders. Another item's id, an unknown id, a check or verdict id fails ``reference``; a repeat ``duplicate``.
21
+ Run summary checks: exactly the keys summary and highlight; summary 1 to the ``summary`` limit of distinct ids of
22
+ ``run_bank`` (a run frame whose counts do not hold fails ``precondition``); highlight up to the ``highlight`` limit of
23
+ distinct item numbers, written as integers, of ``highlightable`` (an item of another verdict fails ``precondition``).
24
+
25
+ Rendering: the Check and Verdict frames; the selected sentences in the model's order, except that remediation steps
26
+ keep their baseline order across the places the model gave steps; then the values listed in show or shown by a
27
+ selected frame, in the item's value order, each quoted and escaped under its fixed label (``LABELS``). The summary
28
+ renders its frames in the model's order and the highlighted items in the rules' order. ``answer_form`` and
29
+ ``summary_form`` give M10-T03's decoding grammar the JSON schema with the allowed id enums; every answer the schema
30
+ admits passes these checks. Pure and deterministic: no model, no network.
31
+ """
32
+ from __future__ import annotations
33
+
34
+ import json
35
+ import re
36
+ from collections.abc import Mapping
37
+ from typing import Any
38
+
39
+ from .answer_digest import (
40
+ CATALOGUE,
41
+ CATALOGUE_ID,
42
+ VERDICT_TEXT,
43
+ frames,
44
+ highlightable,
45
+ item_bank,
46
+ quoted,
47
+ ref_of,
48
+ run_bank,
49
+ )
50
+
51
+ ITEM_KEYS = ("use", "show")
52
+ SUMMARY_KEYS = ("summary", "highlight")
53
+ ALWAYS_SHOWN = ("check", "verdict")
54
+ LABELS = {"check": "Check", "severity": "Severity", "requirement": "Requirement", "reason": "Reason",
55
+ "field": "Field", "setting": "Setting"}
56
+ REF_ID = re.compile(r"v[1-9][0-9]*")
57
+
58
+
59
+ class AnswerCheckError(ValueError):
60
+ """An answer that did not pass the checks was given to the renderer."""
61
+
62
+
63
+ def _parse(answer: Any, keys: tuple[str, str]) -> tuple[Mapping[str, Any] | None, str | None]:
64
+ from azure_tenant_audit.strict_json import reject_json_constant, strict_pairs
65
+
66
+ if isinstance(answer, str):
67
+ try:
68
+ answer = json.loads(answer, object_pairs_hook=strict_pairs, parse_constant=reject_json_constant)
69
+ except (ValueError, RecursionError):
70
+ return None, "the answer is not one JSON object"
71
+ if not isinstance(answer, Mapping):
72
+ return None, "the answer is not one JSON object"
73
+ if set(answer) != set(keys):
74
+ return None, f"the answer's keys are {sorted(map(str, answer))[:6]}, not {' and '.join(keys)}"
75
+ return answer, None
76
+
77
+
78
+ def _id_list(value: Any, kind: type) -> bool:
79
+ return isinstance(value, list) and all(type(entry) is kind for entry in value)
80
+
81
+
82
+ def showable(item: Mapping[str, Any]) -> list[str]:
83
+ """The reference ids an answer may list in ``show``: the item's values other than its check and verdict."""
84
+ return [value["ref"] for value in item["values"] if value["name"] not in ALWAYS_SHOWN]
85
+
86
+
87
+ def answer_form(item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
88
+ """What a decoding grammar may produce for this item (M10-T03): the JSON schema with the allowed id enums, the
89
+ bank's sentences by id and the reference ids for ``show``. ``digest`` is accepted for symmetry with
90
+ ``check_answer``; an item's form depends on the item alone."""
91
+ bank, ids = item_bank(item), showable(item)
92
+ limit = frames()["limits"]["use"]
93
+ schema = {"type": "object", "additionalProperties": False, "required": list(ITEM_KEYS),
94
+ "properties": {"use": {"type": "array", "minItems": 1, "maxItems": min(limit, len(bank)),
95
+ "uniqueItems": True, "items": {"type": "string", "enum": list(bank)}},
96
+ "show": {"type": "array", "maxItems": len(ids), "uniqueItems": True,
97
+ "items": {"type": "string", "enum": ids}}}}
98
+ return {"schema": schema, "sentences": {sid: entry["text"] for sid, entry in bank.items()}, "show": ids,
99
+ "limits": {"use": limit}}
100
+
101
+
102
+ def summary_form(digest: Mapping[str, Any]) -> dict[str, Any]:
103
+ """What a decoding grammar may produce for the run summary: the JSON schema with the run frame and item number
104
+ enums, and the run frames' texts with Auditex's counts."""
105
+ bank, items, limits = run_bank(digest), highlightable(digest), frames()["limits"]
106
+ schema = {"type": "object", "additionalProperties": False, "required": list(SUMMARY_KEYS),
107
+ "properties": {"summary": {"type": "array", "minItems": 1, "maxItems": min(limits["summary"], len(bank)),
108
+ "uniqueItems": True, "items": {"type": "string", "enum": list(bank)}},
109
+ "highlight": {"type": "array", "maxItems": min(limits["highlight"], len(items)),
110
+ "uniqueItems": True, "items": {"type": "integer", "enum": items}}}}
111
+ return {"schema": schema, "sentences": bank, "highlight": items,
112
+ "limits": {"summary": limits["summary"], "highlight": limits["highlight"]}}
113
+
114
+
115
+ def _check_use(use: Any, item: Mapping[str, Any], fail) -> None:
116
+ if not _id_list(use, str):
117
+ fail("form", "use is not a list of sentence ids")
118
+ return
119
+ limit, bank = frames()["limits"]["use"], item_bank(item)
120
+ if not use:
121
+ fail("empty", "use selects no sentence")
122
+ if len(use) > limit:
123
+ fail("limit", f"use selects {len(use)} sentences, more than {limit}")
124
+ seen: set[str] = set()
125
+ for sid in use:
126
+ if sid in seen:
127
+ fail("duplicate", f"use lists {sid} twice")
128
+ elif sid not in bank:
129
+ if sid in frames()["item"] or CATALOGUE_ID.fullmatch(sid):
130
+ fail("precondition", f"{sid} is not in this item's bank (verdict {VERDICT_TEXT[item['verdict']]})")
131
+ else:
132
+ fail("unknown", f"use holds {json.dumps(sid)[:40]}, not a sentence id of this item")
133
+ seen.add(sid)
134
+
135
+
136
+ def _check_show(show: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None, fail) -> None:
137
+ if not _id_list(show, str):
138
+ fail("form", "show is not a list of reference ids")
139
+ return
140
+ own = {value["ref"]: value["name"] for value in item["values"]}
141
+ others = {value["ref"] for entry in (digest["items"] if digest is not None else []) for value in entry["values"]}
142
+ seen: set[str] = set()
143
+ for ref in show:
144
+ if ref in seen:
145
+ fail("duplicate", f"show lists {json.dumps(ref)[:40]} twice")
146
+ elif ref not in own:
147
+ where = ("another item's value" if ref in others else
148
+ "no value of the digest" if REF_ID.fullmatch(ref) else "not a reference id such as v4")
149
+ fail("reference", f"{json.dumps(ref)[:40]} is {where}, not a value of this item")
150
+ elif own[ref] in ALWAYS_SHOWN:
151
+ fail("reference", f"{ref} is the item's {own[ref]}, which Auditex always shows")
152
+ seen.add(ref)
153
+
154
+
155
+ def check_answer(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
156
+ """{"pass": bool, "failures": [{"check", "detail"}]} for the model's answer for one digest item.
157
+
158
+ Checks: form, empty, limit, duplicate, precondition, unknown (use) and reference (show). Pass the whole digest so
159
+ another item's reference ids are named as such.
160
+ """
161
+ failures: list[dict[str, str]] = []
162
+
163
+ def fail(check: str, detail: str) -> None:
164
+ failures.append({"check": check, "detail": detail[:160]})
165
+
166
+ parsed, problem = _parse(answer, ITEM_KEYS)
167
+ if parsed is None:
168
+ fail("form", problem or "the answer is not one JSON object")
169
+ else:
170
+ _check_use(parsed["use"], item, fail)
171
+ _check_show(parsed["show"], item, digest, fail)
172
+ return {"pass": not failures, "failures": failures}
173
+
174
+
175
+ def _check_name(item: Mapping[str, Any]) -> str:
176
+ return next(value["text"] for value in item["values"] if value["name"] == "check")
177
+
178
+
179
+ def _render(item: Mapping[str, Any], use: list[str], show: list[str]) -> str:
180
+ bank = item_bank(item)
181
+ lines = [f"Check: {quoted(_check_name(item))}", f"Verdict: {VERDICT_TEXT[item['verdict']]}."]
182
+ steps = iter(sorted((sid for sid in use if bank[sid]["kind"] == "step"), key=lambda sid: int(sid[5:])))
183
+ lines.extend(bank[next(steps) if bank[sid]["kind"] == "step" else sid]["text"] for sid in use)
184
+ shown = set(show) | {ref_of(item, name) for sid in use for name in bank[sid]["shows"]}
185
+ lines.extend(f"{LABELS[value['name']]}: {quoted(value['text'])}" for value in item["values"]
186
+ if value["ref"] in shown and value["name"] not in ALWAYS_SHOWN)
187
+ return "\n".join(lines)
188
+
189
+
190
+ def render_answer(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> str:
191
+ """The item as Auditex shows it with the model's answer; AnswerCheckError when the answer does not pass."""
192
+ result = check_answer(answer, item, digest)
193
+ if not result["pass"]:
194
+ raise AnswerCheckError("; ".join(f"{f['check']}: {f['detail']}" for f in result["failures"]))
195
+ parsed, _ = _parse(answer, ITEM_KEYS)
196
+ return _render(item, parsed["use"], parsed["show"])
197
+
198
+
199
+ def fallback_text(item: Mapping[str, Any]) -> str:
200
+ """The fixed text an item shows when the model's answer fails the checks: the check and verdict frames, then the
201
+ severity and the reason only when the digest marks them as shipped catalogue text, so tenant data never changes
202
+ it."""
203
+ show = [value["ref"] for value in item["values"]
204
+ if value["name"] in ("severity", "reason") and value.get("source") == CATALOGUE]
205
+ return _render(item, [], show)
206
+
207
+
208
+ def answer_item(answer: Any, item: Mapping[str, Any], digest: Mapping[str, Any] | None = None) -> dict[str, Any]:
209
+ """{"text", "fallback", "failures"}: the item rendered with the model's answer when it passes, else the fixed
210
+ text."""
211
+ result = check_answer(answer, item, digest)
212
+ if result["pass"]:
213
+ parsed, _ = _parse(answer, ITEM_KEYS)
214
+ return {"text": _render(item, parsed["use"], parsed["show"]), "fallback": False, "failures": []}
215
+ return {"text": fallback_text(item), "fallback": True, "failures": result["failures"]}
216
+
217
+
218
+ def check_summary(answer: Any, digest: Mapping[str, Any]) -> dict[str, Any]:
219
+ """{"pass": bool, "failures": [{"check", "detail"}]} for the model's run summary."""
220
+ failures: list[dict[str, str]] = []
221
+
222
+ def fail(check: str, detail: str) -> None:
223
+ failures.append({"check": check, "detail": detail[:160]})
224
+
225
+ parsed, problem = _parse(answer, SUMMARY_KEYS)
226
+ if parsed is None:
227
+ fail("form", problem or "the answer is not one JSON object")
228
+ return {"pass": False, "failures": failures}
229
+ limits, summary, highlight = frames()["limits"], parsed["summary"], parsed["highlight"]
230
+ if not _id_list(summary, str):
231
+ fail("form", "summary is not a list of run frame ids")
232
+ else:
233
+ bank = run_bank(digest)
234
+ if not summary:
235
+ fail("empty", "summary selects no frame")
236
+ if len(summary) > limits["summary"]:
237
+ fail("limit", f"summary selects {len(summary)} frames, more than {limits['summary']}")
238
+ for index, fid in enumerate(summary):
239
+ if fid in summary[:index]:
240
+ fail("duplicate", f"summary lists {fid} twice")
241
+ elif fid not in bank:
242
+ fail("precondition" if fid in frames()["run"] else "unknown",
243
+ f"{json.dumps(fid)[:40]} is not a run frame whose counts hold for this run")
244
+ if not _id_list(highlight, int):
245
+ fail("form", "highlight is not a list of item numbers")
246
+ else:
247
+ allowed, numbers = highlightable(digest), {item["item"] for item in digest["items"]}
248
+ if len(highlight) > limits["highlight"]:
249
+ fail("limit", f"highlight lists {len(highlight)} items, more than {limits['highlight']}")
250
+ for index, number in enumerate(highlight):
251
+ if number in highlight[:index]:
252
+ fail("duplicate", f"highlight lists item {number} twice")
253
+ elif number not in allowed:
254
+ fail("precondition" if number in numbers else "unknown",
255
+ f"item {number} is not an item the summary may highlight")
256
+ return {"pass": not failures, "failures": failures}
257
+
258
+
259
+ def _render_summary(digest: Mapping[str, Any], summary: list[str], highlight: list[int]) -> str:
260
+ bank = run_bank(digest)
261
+ lines = [bank[fid] for fid in summary]
262
+ chosen = [item for item in digest["items"] if item["item"] in set(highlight)]
263
+ if chosen:
264
+ lines.append(frames()["highlight"]["heading"])
265
+ lines.extend(f"Check: {quoted(_check_name(item))}. Verdict: {VERDICT_TEXT[item['verdict']]}."
266
+ for item in chosen)
267
+ return "\n".join(lines)
268
+
269
+
270
+ def fallback_summary(digest: Mapping[str, Any]) -> str:
271
+ """The fixed run summary: every run frame without a precondition, in the frames file's order."""
272
+ unconditional = [fid for fid, frame in frames()["run"].items() if not frame["min"] and not frame["max"]]
273
+ return _render_summary(digest, unconditional, [])
274
+
275
+
276
+ def render_summary(answer: Any, digest: Mapping[str, Any]) -> str:
277
+ """The run summary as Auditex shows it with the model's answer; AnswerCheckError when it does not pass."""
278
+ result = check_summary(answer, digest)
279
+ if not result["pass"]:
280
+ raise AnswerCheckError("; ".join(f"{f['check']}: {f['detail']}" for f in result["failures"]))
281
+ parsed, _ = _parse(answer, SUMMARY_KEYS)
282
+ return _render_summary(digest, parsed["summary"], parsed["highlight"])
283
+
284
+
285
+ def answer_summary(answer: Any, digest: Mapping[str, Any]) -> dict[str, Any]:
286
+ """{"text", "fallback", "failures"}: the run summary with the model's answer when it passes, else the fixed one."""
287
+ result = check_summary(answer, digest)
288
+ if result["pass"]:
289
+ parsed, _ = _parse(answer, SUMMARY_KEYS)
290
+ return {"text": _render_summary(digest, parsed["summary"], parsed["highlight"]), "fallback": False,
291
+ "failures": []}
292
+ return {"text": fallback_summary(digest), "fallback": True, "failures": result["failures"]}