Files
goclaw/internal/gateway/methods/audit.go
T
viettranx 9115169c03 feat: expand audit logging via pub/sub event pattern
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.
2026-03-12 18:34:56 +07:00

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(),
},
})
}