audit

package
v0.0.0-...-b198e9d Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryOptions

type QueryOptions struct {
	// Time range
	StartTime *time.Time
	EndTime   *time.Time

	// Filters
	AgentID   string
	SessionID string
	Method    string
	Tool      string
	Allowed   *bool

	// Pagination
	Limit  int
	Offset int

	// Ordering
	OrderBy   string // "timestamp", "agent_id", etc.
	OrderDesc bool
}

QueryOptions for filtering audit records.

type Record

type Record struct {
	// Identifiers
	ID        int64  `json:"id"`
	RequestID string `json:"request_id"`
	SessionID string `json:"session_id"`

	// Timing
	Timestamp time.Time `json:"timestamp"`
	Latency   float64   `json:"latency_ms"`

	// Agent info
	AgentID      string `json:"agent_id"`
	AgentName    string `json:"agent_name,omitempty"`
	Capabilities string `json:"capabilities,omitempty"` // JSON array as string

	// Request info
	Method      string `json:"method"`
	Tool        string `json:"tool,omitempty"`
	ResourceURI string `json:"resource_uri,omitempty"`
	Arguments   string `json:"arguments,omitempty"` // JSON as string

	// Identity info
	IdentityVerified bool   `json:"identity_verified"`
	DID              string `json:"did,omitempty"`

	// Policy decision
	Allowed     bool   `json:"allowed"`
	MatchedRule string `json:"matched_rule,omitempty"`
	Violations  string `json:"violations,omitempty"` // JSON array as string
	PolicyMode  string `json:"policy_mode"`

	// Environment
	SourceIP    string `json:"source_ip,omitempty"`
	Environment string `json:"environment,omitempty"`
}

Record represents a single audit log entry.

type RecordBuilder

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

RecordBuilder helps construct audit records.

func NewRecordBuilder

func NewRecordBuilder() *RecordBuilder

NewRecordBuilder creates a new record builder.

func (*RecordBuilder) Build

func (b *RecordBuilder) Build() *Record

Build returns the constructed record.

func (*RecordBuilder) WithAgent

func (b *RecordBuilder) WithAgent(agentID, agentName, capabilities string) *RecordBuilder

WithAgent sets agent information.

func (*RecordBuilder) WithDecision

func (b *RecordBuilder) WithDecision(allowed bool, matchedRule, violations, policyMode string) *RecordBuilder

WithDecision sets the policy decision.

func (*RecordBuilder) WithEnvironment

func (b *RecordBuilder) WithEnvironment(sourceIP, environment string) *RecordBuilder

WithEnvironment sets environment context.

func (*RecordBuilder) WithIdentity

func (b *RecordBuilder) WithIdentity(verified bool, did string) *RecordBuilder

WithIdentity sets identity information.

func (*RecordBuilder) WithMethod

func (b *RecordBuilder) WithMethod(method, tool, resourceURI, arguments string) *RecordBuilder

WithMethod sets the request method and details.

func (*RecordBuilder) WithRequest

func (b *RecordBuilder) WithRequest(requestID, sessionID string) *RecordBuilder

WithRequest sets request identifiers.

func (*RecordBuilder) WithTiming

func (b *RecordBuilder) WithTiming(latencyMs float64) *RecordBuilder

WithTiming sets timing information.

type Stats

type Stats struct {
	TotalRequests   int64   `json:"total_requests"`
	AllowedRequests int64   `json:"allowed_requests"`
	DeniedRequests  int64   `json:"denied_requests"`
	UniqueAgents    int64   `json:"unique_agents"`
	UniqueSessions  int64   `json:"unique_sessions"`
	AvgLatencyMs    float64 `json:"avg_latency_ms"`
}

Stats contains aggregate statistics.

type Store

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

Store provides SQLite-based audit log storage.

func NewStore

func NewStore(cfg StoreConfig) (*Store, error)

NewStore creates a new SQLite audit store.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) GetStats

func (s *Store) GetStats(ctx context.Context, since *time.Time) (*Stats, error)

GetStats returns aggregate statistics.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, record *Record) error

Insert adds a single audit record.

func (*Store) InsertBatch

func (s *Store) InsertBatch(ctx context.Context, records []*Record) error

InsertBatch inserts multiple records in a single transaction.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, olderThan time.Duration) (int64, error)

Prune removes records older than the specified duration.

func (*Store) Query

func (s *Store) Query(ctx context.Context, opts QueryOptions) ([]*Record, error)

Query retrieves audit records based on options.

type StoreConfig

type StoreConfig struct {
	DBPath string // Path to SQLite file, ":memory:" for in-memory
}

StoreConfig holds configuration for the audit store.

type Writer

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

Writer provides async buffered writing of audit records.

func NewWriter

func NewWriter(store *Store, cfg WriterConfig) *Writer

NewWriter creates a new async audit writer.

func (*Writer) Flush

func (w *Writer) Flush()

Flush forces an immediate flush of the buffer.

func (*Writer) Start

func (w *Writer) Start()

Start begins the background flush loop.

func (*Writer) Stats

func (w *Writer) Stats() WriterStats

Stats returns current writer statistics.

func (*Writer) Stop

func (w *Writer) Stop()

Stop stops the writer and flushes remaining records.

func (*Writer) Write

func (w *Writer) Write(record *Record)

Write adds a record to the buffer.

type WriterConfig

type WriterConfig struct {
	BufferSize    int           // Max records to buffer before flush
	FlushInterval time.Duration // How often to flush
}

WriterConfig holds configuration for the audit writer.

type WriterStats

type WriterStats struct {
	Written    int64
	Dropped    int64
	Flushes    int64
	BufferSize int
}

WriterStats contains writer statistics.

Jump to

Keyboard shortcuts

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