mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-10 12:10:53 +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.
35 lines
796 B
Go
35 lines
796 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/bus"
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
"github.com/nextlevelbuilder/goclaw/pkg/protocol"
|
|
)
|
|
|
|
// emitAudit broadcasts an audit event via msgBus for async persistence.
|
|
func emitAudit(msgBus *bus.MessageBus, r *http.Request, action, entityType, entityID string) {
|
|
if msgBus == nil {
|
|
return
|
|
}
|
|
actorID := store.UserIDFromContext(r.Context())
|
|
if actorID == "" {
|
|
actorID = extractUserID(r)
|
|
}
|
|
if actorID == "" {
|
|
actorID = "system"
|
|
}
|
|
msgBus.Broadcast(bus.Event{
|
|
Name: protocol.EventAuditLog,
|
|
Payload: bus.AuditEventPayload{
|
|
ActorType: "user",
|
|
ActorID: actorID,
|
|
Action: action,
|
|
EntityType: entityType,
|
|
EntityID: entityID,
|
|
IPAddress: r.RemoteAddr,
|
|
},
|
|
})
|
|
}
|