refactor(auditor): share audit dispatch logic between control plane and CAS#3191
refactor(auditor): share audit dispatch logic between control plane and CAS#3191migmartri wants to merge 1 commit into
Conversation
…nd CAS Extract the generate -> publish -> error-reporting flow shared by the control plane's biz.AuditorUseCase and the Artifact CAS AuditDispatcher into a new auditor.Dispatcher in the importable pkg/auditor package. Both callers now delegate the common machinery and keep only their own actor and organization resolution (request context vs JWT claims). Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 645d8cdc-ff37-4ed7-a529-055bc20b46e7
AI Session Analysis
|
| Status | Attribution | File | Lines |
|---|---|---|---|
| created | ai | app/controlplane/pkg/auditor/dispatcher_test.go |
+131 / -0 |
| modified | ai | app/artifact-cas/internal/service/auditor_test.go |
+50 / -34 |
| created | ai | app/controlplane/pkg/auditor/dispatcher.go |
+80 / -0 |
| modified | ai | app/artifact-cas/internal/service/auditor.go |
+18 / -30 |
| modified | ai | app/controlplane/pkg/biz/auditor.go |
+15 / -18 |
Policies (4)
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | ai-config-ai-agents-allowed |
ai-coding-session-645d8c |
- |
| ✅ Passed | ai-config-no-dangerous-commands |
ai-coding-session-645d8c |
- |
| ✅ Passed | ai-config-no-secrets |
ai-coding-session-645d8c |
- |
| ✅ Passed | ai-config-mcp-servers-allowed |
ai-coding-session-645d8c |
- |
Powered by Chainloop and Chainloop Trace
Follow-up to #3189 addressing @jiparis's review comment asking whether the CAS could reuse the control plane's audit dispatcher instead of carrying its own copy of the dispatch logic.
The truly shared part — generate the audit event, publish it, and report failures to the log and Sentry — is now extracted into a new
auditor.Dispatcherin the importableapp/controlplane/pkg/auditorpackage. Both the control plane'sbiz.AuditorUseCaseand the Artifact CASAuditDispatcherdelegate to it.Each caller keeps only what genuinely differs between them: actor and organization resolution. The control plane resolves the actor from the request context (user, API token or system) and the CAS uses a SYSTEM actor with the organization taken from the JWT claims. The CAS does not import
bizdirectly, which would pull the full control-plane dependency graph into the CAS binary; the reusable seam is the lower-level dispatcher inpkg/auditor.AI disclosure
This contribution was developed with AI assistance (Claude Code).
cc @jiparis
🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri