audit

package
v1.1.68-test Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type Action struct {
	Type string `json:"type,omitempty"`
	Data any    `json:"data,omitempty"`
}

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

func New(baseURL string, disabled bool, token string) *Client

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.

type Result

type Result struct {
	Status  string `json:"status,omitempty"`
	Message string `json:"message,omitempty"`
}

Result is the outcome status/message. Mirrors types.ts EventResult.

type Subject

type Subject struct {
	Name   string `json:"name,omitempty"`
	Claims any    `json:"claims,omitempty"`
	Data   any    `json:"data,omitempty"`
}

Subject identifies the acting principal. Mirrors types.ts EventSubject.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL