Documentation
¶
Overview ¶
Package audit provides a small, reusable client for emitting audit EVENTS to the Control Plane audit service (POST /audit/org/{org}/auditctx/cpln). It is the emitter counterpart to go-libs/api/auditctx.go (which manages audit-context RESOURCES). The event shape mirrors the audit service's canonical model (audit/pkg/types/models.go) and the data-service TypeScript type (data-service/src/audit/types.ts) so the JSON is consumed unchanged.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action describes what happened (create/edit/delete/reveal/…). Mirrors types.ts EventAction.
type AuditEvent ¶
type AuditEvent struct {
EventTime string `json:"eventTime,omitempty"`
RequestID string `json:"requestId,omitempty"`
Context *Context `json:"context,omitempty"`
Subject *Subject `json:"subject,omitempty"`
Resource *Resource `json:"resource,omitempty"`
Action *Action `json:"action,omitempty"`
Result *Result `json:"result,omitempty"`
}
AuditEvent is the audit record posted to the audit service. Field names/JSON tags match audit/pkg/types.AuditEvent (the canonical server type) and the TS AuditEvent, so the emitted JSON is identical to what the TS service sends.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client emits audit events to the audit service. It is fire-and-forget: Write never blocks the caller and never returns an error — a failed post is logged and swallowed (matching the TS AuditService.write .catch()). A disabled client is a no-op. Zero-value is not usable; construct with New.
func New ¶
New builds a Client. baseURL is the audit service origin (e.g. "http://localhost:43000"); Write posts to {baseURL}/audit/org/{org}/auditctx/cpln?async=true — the same path the TS service and terminal-server use. When disabled is true every Write is a no-op. token, when non-empty, is sent as a Bearer Authorization header (the audit service's public endpoint requires it; the data-service sidecar does not, so it passes "").
func (*Client) Write ¶
func (c *Client) Write(_ context.Context, ev *AuditEvent)
Write marshals the event now, so a caller may mutate what it references once Write returns, and posts it on a goroutine with a detached context, so the round-trip never adds latency to or fails the caller's request. Errors are logged at info and swallowed. No-op when the client is disabled or the event is nil.
type Context ¶
type Context struct {
RemoteIP string `json:"remoteIp,omitempty"`
EventSource string `json:"eventSource,omitempty"`
Org string `json:"org,omitempty"`
Data any `json:"data,omitempty"`
}
Context carries request/environment facts. Mirrors types.ts EventContext and the subset of audit types.Context that the data-service emitter populates.
type Resource ¶
type Resource struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Data any `json:"data,omitempty"`
}
Resource identifies the target of the action. Mirrors types.ts EventResource.