audit

package
v0.4.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActorStats

type ActorStats struct {
	ActorID    string `json:"actor_id"`
	ActorType  string `json:"actor_type"`
	EventCount int    `json:"event_count"`
	LastSeen   string `json:"last_seen"`
}

type ActorType

type ActorType string
const (
	ActorTypeAPIKey    ActorType = "api_key"
	ActorTypeJWT       ActorType = "jwt"
	ActorTypeSystem    ActorType = "system"
	ActorTypeAnonymous ActorType = "anonymous"
)

type AuditEvent

type AuditEvent struct {
	ID             int64     `json:"id"`
	EventID        string    `json:"event_id"`
	Timestamp      time.Time `json:"timestamp"`
	ActorType      ActorType `json:"actor_type"`
	ActorID        string    `json:"actor_id,omitempty"`
	ActorName      string    `json:"actor_name,omitempty"`
	APIKeyPrefix   string    `json:"api_key_prefix,omitempty"`
	Action         string    `json:"action"`
	Method         string    `json:"method"`
	Path           string    `json:"path"`
	ResourceType   string    `json:"resource_type,omitempty"`
	ResourceID     string    `json:"resource_id,omitempty"`
	ClientIP       string    `json:"client_ip"`
	UserAgent      string    `json:"user_agent,omitempty"`
	RequestID      string    `json:"request_id,omitempty"`
	RequestBody    string    `json:"request_body,omitempty"`
	ResponseStatus int       `json:"response_status"`
	ResponseTimeMs int64     `json:"response_time_ms"`
	Success        bool      `json:"success"`
	ErrorMessage   string    `json:"error_message,omitempty"`
	Metadata       string    `json:"metadata,omitempty"`
}

type AuditFilter

type AuditFilter struct {
	ActorID      string
	ActorType    ActorType
	Action       string
	ResourceType string
	ResourceID   string
	Success      *bool
	ClientIP     string
	StartTime    time.Time
	EndTime      time.Time
	Limit        int
	Offset       int
}

type AuditStats

type AuditStats struct {
	TotalEvents    int            `json:"total_events"`
	Last24Hours    int            `json:"last_24_hours"`
	Last7Days      int            `json:"last_7_days"`
	ByAction       map[string]int `json:"by_action"`
	ByActorType    map[string]int `json:"by_actor_type"`
	ByResourceType map[string]int `json:"by_resource_type"`
	FailureCount   int            `json:"failure_count"`
	TopActors      []ActorStats   `json:"top_actors"`
	EventsTrend    []TrendPoint   `json:"events_trend"`
}

type Config

type Config struct {
	Enabled            bool
	RetentionDays      int
	CaptureRequestBody bool
	ExcludedPaths      []string
	SensitiveFields    []string
	CleanupInterval    time.Duration
}

type DB

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

func NewDB

func NewDB(deploymentsPath string) (*DB, error)

func (*DB) CleanupOldEvents

func (db *DB) CleanupOldEvents(olderThan time.Duration) (int64, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) GetEventByEventID

func (db *DB) GetEventByEventID(eventID string) (*AuditEvent, error)

func (*DB) GetEventByID

func (db *DB) GetEventByID(id int64) (*AuditEvent, error)

func (*DB) GetEvents

func (db *DB) GetEvents(filter *AuditFilter) ([]AuditEvent, int, error)

func (*DB) GetStats

func (db *DB) GetStats() (*AuditStats, error)

func (*DB) InsertEvent

func (db *DB) InsertEvent(event *AuditEvent) (int64, error)

type Manager

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

func NewManager

func NewManager(deploymentsPath string, config *Config) (*Manager, error)

func (*Manager) Cleanup

func (m *Manager) Cleanup() (int64, error)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) ExportEvents

func (m *Manager) ExportEvents(filter *AuditFilter, format string) ([]byte, error)

func (*Manager) GetEventByEventID

func (m *Manager) GetEventByEventID(eventID string) (*AuditEvent, error)

func (*Manager) GetEventByID

func (m *Manager) GetEventByID(id int64) (*AuditEvent, error)

func (*Manager) GetEvents

func (m *Manager) GetEvents(filter *AuditFilter) ([]AuditEvent, int, error)

func (*Manager) GetStats

func (m *Manager) GetStats() (*AuditStats, error)

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

func (*Manager) LogEvent

func (m *Manager) LogEvent(event *AuditEvent) error

func (*Manager) ShouldCaptureBody

func (m *Manager) ShouldCaptureBody() bool

func (*Manager) ShouldCapturePath

func (m *Manager) ShouldCapturePath(path string) bool

type Middleware

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

func NewMiddleware

func NewMiddleware(manager *Manager) *Middleware

func (*Middleware) Capture

func (m *Middleware) Capture() gin.HandlerFunc

type TrendPoint

type TrendPoint struct {
	Date  string `json:"date"`
	Count int    `json:"count"`
}

Jump to

Keyboard shortcuts

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