auditmanager

package
v0.0.0-...-8c930d8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditManager

type AuditManager struct {
	// contains filtered or unexported fields
}

AuditManager writes the operation log: one entry per operation the configuration does not exclude, written by the handler that performed it, before the request answers. It holds the audit configuration and nothing else — no buffer, no goroutine — so a record that was asked for either reaches the table or is reported as failed.

func New

func New(auditConfig *config.Audit) *AuditManager

New creates an audit manager that reads auditConfig on every call, so a configuration reloaded in place takes effect without rebuilding it.

func (*AuditManager) Enabled

func (am *AuditManager) Enabled(op types.Operation) bool

Enabled reports whether the log records op: the audit is on and op is not excluded. A flow asks it before reading what only the entry needs, so a disabled audit costs no query.

func (*AuditManager) RecordOperation

func (am *AuditManager) RecordOperation(ctx context.Context, m types.Model, op types.Operation,
	build func() *modellogmgmt.OperationLog,
) error

RecordOperation records a single operation audit log, leaving out what the configuration excludes.

The entry is produced by build rather than handed in, because building one is the expensive part: it serializes the record, reads the request and allocates the entry. Auditing is disabled by default, and a call whose argument is already built pays that price on every write request only to have it discarded here. build runs once the entry is known to be wanted, so a disabled audit costs this call and nothing else.

op is taken separately for the same reason: it decides whether the operation is excluded, so it has to be known before build runs. It is stamped onto the entry here, which keeps the caller from naming the operation twice.

A nil build is an error rather than a silent skip: an audit entry that was asked for and never written is a gap in a security record.

The write runs on a context derived from ctx, which keeps what the request carries — the trace the statement is annotated with, the identity every log line takes — and leaves its cancellation behind: the operation the entry records has already happened, and a client that went away must not take the record of it with it. writeTimeout bounds the write instead. A failure is counted and returned to the caller, which logs it beside the request.

Jump to

Keyboard shortcuts

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