accesslogs

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPageSize is the default number of records per page
	DefaultPageSize = 50
	// MaxPageSize is the maximum number of records allowed per page
	MaxPageSize = 100

	// Default sorting
	DefaultSortBy    = "timestamp"
	DefaultSortOrder = "desc"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLogEntry

type AccessLogEntry struct {
	ID             string        `gorm:"primaryKey"`
	AccountID      string        `gorm:"index"`
	ServiceID      string        `gorm:"index"`
	Timestamp      time.Time     `gorm:"index"`
	GeoLocation    peer.Location `gorm:"embedded;embeddedPrefix:location_"`
	Method         string        `gorm:"index"`
	Host           string        `gorm:"index"`
	Path           string        `gorm:"index"`
	Duration       time.Duration `gorm:"index"`
	StatusCode     int           `gorm:"index"`
	Reason         string
	UserId         string `gorm:"index"`
	AuthMethodUsed string `gorm:"index"`
}

func (*AccessLogEntry) FromProto

func (a *AccessLogEntry) FromProto(serviceLog *proto.AccessLog)

FromProto creates an AccessLogEntry from a proto.AccessLog

func (*AccessLogEntry) ToAPIResponse

func (a *AccessLogEntry) ToAPIResponse() *api.ProxyAccessLog

ToAPIResponse converts an AccessLogEntry to the API ProxyAccessLog type

type AccessLogFilter

type AccessLogFilter struct {
	// Page is the current page number (1-indexed)
	Page int
	// PageSize is the number of records per page
	PageSize int

	// Sorting parameters
	SortBy    string // Field to sort by: timestamp, url, host, path, method, status_code, duration, source_ip, user_id, auth_method, reason
	SortOrder string // Sort order: asc or desc (default: desc)

	// Filtering parameters
	Search     *string    // General search across log ID, host, path, source IP, and user fields
	SourceIP   *string    // Filter by source IP address
	Host       *string    // Filter by host header
	Path       *string    // Filter by request path (supports LIKE pattern)
	UserID     *string    // Filter by authenticated user ID
	UserEmail  *string    // Filter by user email (requires user lookup)
	UserName   *string    // Filter by user name (requires user lookup)
	Method     *string    // Filter by HTTP method
	Status     *string    // Filter by status: "success" (2xx/3xx) or "failed" (1xx/4xx/5xx)
	StatusCode *int       // Filter by HTTP status code
	StartDate  *time.Time // Filter by timestamp >= start_date
	EndDate    *time.Time // Filter by timestamp <= end_date
}

AccessLogFilter holds pagination, filtering, and sorting parameters for access logs

func (*AccessLogFilter) GetLimit

func (f *AccessLogFilter) GetLimit() int

GetLimit returns the page size for database queries

func (*AccessLogFilter) GetOffset

func (f *AccessLogFilter) GetOffset() int

GetOffset calculates the database offset for pagination

func (*AccessLogFilter) GetSortColumn added in v0.66.0

func (f *AccessLogFilter) GetSortColumn() string

GetSortColumn returns the validated database column name for sorting

func (*AccessLogFilter) GetSortOrder added in v0.66.0

func (f *AccessLogFilter) GetSortOrder() string

GetSortOrder returns the validated sort order (ASC or DESC)

func (*AccessLogFilter) ParseFromRequest

func (f *AccessLogFilter) ParseFromRequest(r *http.Request)

ParseFromRequest parses pagination, sorting, and filter parameters from HTTP request query parameters

type Manager

type Manager interface {
	SaveAccessLog(ctx context.Context, proxyLog *AccessLogEntry) error
	GetAllAccessLogs(ctx context.Context, accountID, userID string, filter *AccessLogFilter) ([]*AccessLogEntry, int64, error)
	CleanupOldAccessLogs(ctx context.Context, retentionDays int) (int64, error)
	StartPeriodicCleanup(ctx context.Context, retentionDays, cleanupIntervalHours int)
	StopPeriodicCleanup()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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