mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-12 02:10:56 +00:00
9115169c03
Replace direct ActivityStore injection with event-driven audit system. Handlers emit audit events via msgBus.Broadcast(), a single subscriber with buffered channel persists to activity_logs table. Coverage expanded from 3 agent CRUD actions to ~65 audit points across all HTTP handlers and WebSocket RPC methods including agents, providers, skills, MCP servers, cron, sessions, teams, pairing, and more.
26 lines
661 B
Go
26 lines
661 B
Go
package methods
|
|
|
|
import (
|
|
"github.com/nextlevelbuilder/goclaw/internal/bus"
|
|
"github.com/nextlevelbuilder/goclaw/internal/gateway"
|
|
"github.com/nextlevelbuilder/goclaw/pkg/protocol"
|
|
)
|
|
|
|
// emitAudit broadcasts an audit event via eventBus for async persistence.
|
|
func emitAudit(pub bus.EventPublisher, client *gateway.Client, action, entityType, entityID string) {
|
|
if pub == nil {
|
|
return
|
|
}
|
|
pub.Broadcast(bus.Event{
|
|
Name: protocol.EventAuditLog,
|
|
Payload: bus.AuditEventPayload{
|
|
ActorType: "user",
|
|
ActorID: client.UserID(),
|
|
Action: action,
|
|
EntityType: entityType,
|
|
EntityID: entityID,
|
|
IPAddress: client.RemoteAddr(),
|
|
},
|
|
})
|
|
}
|