audit

package
v0.0.0-...-706b979 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(logger *Logger, includeReads bool) fiber.Handler

Middleware returns a Fiber middleware that logs auditable requests

Types

type AuditEntry

type AuditEntry struct {
	ID          int64     `json:"id"`
	Timestamp   time.Time `json:"timestamp"`
	EventType   string    `json:"event_type"`
	Actor       string    `json:"actor"`
	Method      string    `json:"method"`
	Path        string    `json:"path"`
	Database    string    `json:"database,omitempty"`
	Measurement string    `json:"measurement,omitempty"`
	StatusCode  int       `json:"status_code"`
	IPAddress   string    `json:"ip_address"`
	UserAgent   string    `json:"user_agent"`
	DurationMs  int64     `json:"duration_ms"`
	Detail      string    `json:"detail,omitempty"`
}

AuditEntry is a stored audit log entry with ID

type AuditEvent

type AuditEvent struct {
	Timestamp   time.Time         `json:"timestamp"`
	EventType   string            `json:"event_type"`
	Actor       string            `json:"actor"`
	Method      string            `json:"method"`
	Path        string            `json:"path"`
	Database    string            `json:"database,omitempty"`
	Measurement string            `json:"measurement,omitempty"`
	StatusCode  int               `json:"status_code"`
	IPAddress   string            `json:"ip_address"`
	UserAgent   string            `json:"user_agent"`
	DurationMs  int64             `json:"duration_ms"`
	Detail      map[string]string `json:"detail,omitempty"`
}

AuditEvent represents a single auditable action

type Logger

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

Logger is the core audit logging service

func NewLogger

func NewLogger(cfg *LoggerConfig) (*Logger, error)

NewLogger creates a new audit logger

func (*Logger) LogEvent

func (l *Logger) LogEvent(event *AuditEvent)

LogEvent queues an audit event for async writing

func (*Logger) Query

func (l *Logger) Query(ctx context.Context, filter *QueryFilter) ([]AuditEntry, error)

Query retrieves audit log entries matching the given filter

func (*Logger) Start

func (l *Logger) Start() error

Start starts the background writer and retention cleanup goroutines

func (*Logger) Stats

func (l *Logger) Stats(ctx context.Context, since time.Time) (map[string]int64, error)

Stats returns aggregate counts by event type

func (*Logger) Stop

func (l *Logger) Stop() error

Stop gracefully shuts down the audit logger

type LoggerConfig

type LoggerConfig struct {
	DB     *sql.DB
	Config *config.AuditLogConfig
	Logger zerolog.Logger
}

LoggerConfig holds configuration for creating an audit logger

type QueryFilter

type QueryFilter struct {
	EventType string
	Actor     string
	Database  string
	Since     time.Time
	Until     time.Time
	Limit     int
	Offset    int
}

QueryFilter holds filter parameters for querying audit logs

Jump to

Keyboard shortcuts

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