audit

package
v0.0.0-...-443440a Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package audit provides audit logging types and storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// ID is the unique identifier for this audit entry.
	ID string `json:"id"`
	// Timestamp is when the request was processed.
	Timestamp time.Time `json:"timestamp"`
	// User is the authenticated subject (from JWT sub claim).
	User string `json:"user"`
	// Roles are the roles from the JWT token.
	Roles []string `json:"roles"`
	// Method is the HTTP method (GET, POST, PUT, DELETE).
	Method string `json:"method"`
	// Path is the request URL path.
	Path string `json:"path"`
	// OperationID is the OpenAPI operation ID (if available).
	OperationID string `json:"operation_id,omitempty"`
	// SourceIP is the client's IP address.
	SourceIP string `json:"source_ip"`
	// ResponseCode is the HTTP response status code.
	ResponseCode int `json:"response_code"`
	// DurationMs is the request processing time in milliseconds.
	DurationMs int64 `json:"duration_ms"`
	// TraceID is the OpenTelemetry trace ID for correlation.
	TraceID string `json:"trace_id,omitempty"`
}

Entry represents a single audit log record.

type Publisher

type Publisher interface {
	Publish(
		ctx context.Context,
		subject string,
		data []byte,
	) error
}

Publisher defines the interface for publishing messages to NATS subjects.

type Store

type Store interface {
	// Write persists an audit entry.
	Write(
		ctx context.Context,
		entry Entry,
	) error

	// Get retrieves a single audit entry by ID.
	Get(
		ctx context.Context,
		id string,
	) (*Entry, error)

	// List retrieves audit entries with pagination.
	// Returns the entries, total count, and any error.
	List(
		ctx context.Context,
		limit int,
		offset int,
	) ([]Entry, int, error)

	// ListAll retrieves all audit entries without pagination.
	ListAll(
		ctx context.Context,
	) ([]Entry, error)
}

Store defines the interface for audit log persistence.

type StreamStore

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

StreamStore implements Store backed by a NATS JetStream stream.

func NewStreamStore

func NewStreamStore(
	logger *slog.Logger,
	stream jetstream.Stream,
	publisher Publisher,
	subject string,
) *StreamStore

NewStreamStore creates a new StreamStore.

func (*StreamStore) Get

func (s *StreamStore) Get(
	ctx context.Context,
	id string,
) (*Entry, error)

Get retrieves a single audit entry by ID.

func (*StreamStore) List

func (s *StreamStore) List(
	ctx context.Context,
	limit int,
	offset int,
) ([]Entry, int, error)

List retrieves audit entries with pagination, newest-first. Returns the entries, total count, and any error.

func (*StreamStore) ListAll

func (s *StreamStore) ListAll(
	ctx context.Context,
) ([]Entry, error)

ListAll retrieves all audit entries without pagination, newest-first.

func (*StreamStore) Write

func (s *StreamStore) Write(
	ctx context.Context,
	entry Entry,
) error

Write persists an audit entry by publishing to the stream.

Directories

Path Synopsis
Package export provides pluggable audit log export with pagination.
Package export provides pluggable audit log export with pagination.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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