auditlogs

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: GPL-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuditLogFilterID           = "id"
	AuditLogFilterType         = "type"
	AuditLogFilterLevel_EQ     = "level_eq"
	AuditLogFilterLevel_GT     = "level_gt"
	AuditLogFilterLevel_LT     = "level_lt"
	AuditLogFilterTimestamp_EQ = "timestamp_eq"
	AuditLogFilterTimestamp_GT = "timestamp_gt"
	AuditLogFilterTimestamp_LT = "timestamp_lt"
	AuditLogFilterUserID       = "user_id"
	AuditLogFilterObjectID     = "object_id"
	AuditLogFilterContentType  = "content_type"
	AuditLogFilterData         = "data"
)

Variables

View Source
var (
	ErrLogEntryNotFound = errors.New("log entry not found")
	ErrLogsNotReady     = errors.New("audit logs app not ready")

	LogUnknownTypes bool = false
)

Functions

func Log

func Log(entryType string, level logger.LogLevel, forObject attrs.Definer, data map[string]interface{}) (uuid.UUID, error)

func NewAppConfig

func NewAppConfig() django.AppConfig

func RegisterBackend

func RegisterBackend(backend StorageBackend)

func RegisterDefinition

func RegisterDefinition(typ string, definition Definition)

func RegisterFilter

func RegisterFilter(filter EntryFilter)

func RegisterFilterForObject

func RegisterFilterForObject(filter EntryFilter, contentType contenttypes.ContentType)

func RegisterHandler

func RegisterHandler(handler EntryHandler)

func RegisterHandlerForObject

func RegisterHandlerForObject(handler EntryHandler, contentType contenttypes.ContentType)

func SerializeRow

func SerializeRow(l LogEntry) (id uuid.UUID, typeStr string, level int, timestamp time.Time, userId, objectID []byte, contentType contenttypes.ContentType, data string)

Types

type AuditLogFilter

type AuditLogFilter interface {
	Is(string) bool
	Name() string
	Value() []interface{}
}

func FilterContentType

func FilterContentType(values ...contenttypes.ContentType) AuditLogFilter

func FilterData

func FilterData(values ...interface{}) AuditLogFilter

func FilterLevelEqual

func FilterLevelEqual(values ...logger.LogLevel) AuditLogFilter

func FilterLevelGreaterThan

func FilterLevelGreaterThan(value logger.LogLevel) AuditLogFilter

func FilterLevelLessThan

func FilterLevelLessThan(value logger.LogLevel) AuditLogFilter

func FilterObjectID

func FilterObjectID(values ...interface{}) AuditLogFilter

func FilterTimestampEqual

func FilterTimestampEqual(values ...time.Time) AuditLogFilter

func FilterType

func FilterType(values ...string) AuditLogFilter

func FilterUserID

func FilterUserID(values ...interface{}) AuditLogFilter

func NewAuditLogFilter

func NewAuditLogFilter(name string, value ...interface{}) AuditLogFilter

type AuditLogs

type AuditLogs struct {
	*apps.AppConfig
}
var Logs *AuditLogs = &AuditLogs{
	AppConfig: apps.NewAppConfig("auditlogs"),
}

type BaseAction

type BaseAction struct {
	DisplayLabel string
	ActionIcon   string
	ActionURL    string
}

func (*BaseAction) Icon

func (ba *BaseAction) Icon() string

func (*BaseAction) Label

func (ba *BaseAction) Label() string

func (*BaseAction) URL

func (ba *BaseAction) URL() string

type BoundDefinition

type BoundDefinition struct {
	Request    *http.Request
	Definition Definition
	LogEntry
}

func Define

func Define(r *http.Request, l LogEntry) *BoundDefinition

func (BoundDefinition) Actions

func (bd BoundDefinition) Actions() []LogEntryAction

func (BoundDefinition) Label

func (bd BoundDefinition) Label() string

func (BoundDefinition) Message

func (bd BoundDefinition) Message() string

type Definition

type Definition interface {
	GetLabel(r *http.Request, logEntry LogEntry) string
	FormatMessage(r *http.Request, logEntry LogEntry) string
	GetActions(r *http.Request, logEntry LogEntry) []LogEntryAction
}

func SimpleDefinition

func SimpleDefinition() Definition

type Entry

type Entry struct {
	Id    uuid.UUID                `db:"id" json:"id"`
	Typ   string                   `db:"type" json:"type"`
	Lvl   logger.LogLevel          `db:"level" json:"level"`
	Time  time.Time                `db:"timestamp" json:"timestamp"`
	UsrID interface{}              `db:"user_id" json:"user_id"`
	Obj   interface{}              `json:"-"`
	ObjID interface{}              `db:"object_id" json:"object_id"`
	CType contenttypes.ContentType `db:"content_type" json:"content_type"`
	Src   map[string]interface{}   `db:"data" json:"data"`
}

func (*Entry) ContentType

func (l *Entry) ContentType() contenttypes.ContentType

func (*Entry) Data

func (l *Entry) Data() map[string]interface{}

func (*Entry) ID

func (l *Entry) ID() uuid.UUID

func (*Entry) Level

func (l *Entry) Level() logger.LogLevel

func (*Entry) Object

func (l *Entry) Object() interface{}

func (*Entry) ObjectID

func (l *Entry) ObjectID() interface{}

func (*Entry) String

func (l *Entry) String() string

func (*Entry) Timestamp

func (l *Entry) Timestamp() time.Time

func (*Entry) Type

func (l *Entry) Type() string

func (*Entry) UserID

func (l *Entry) UserID() interface{}

type EntryFilter

type EntryFilter interface {
	Type() string
	EntryFilter(message LogEntry) bool
}

type EntryHandler

type EntryHandler interface {
	Type() string
	Handle(w io.Writer, message LogEntry) error
}

type LogEntry

type LogEntry interface {
	ID() uuid.UUID
	Type() string
	Level() logger.LogLevel
	Timestamp() time.Time
	UserID() interface{}
	ObjectID() interface{}
	ContentType() contenttypes.ContentType
	Data() map[string]interface{}
}

func ScanRow

func ScanRow(row interface{ Scan(dest ...any) error }) (LogEntry, error)

type LogEntryAction

type LogEntryAction interface {
	Icon() string
	Label() string
	URL() string
}

type StorageBackend

type StorageBackend interface {
	Setup() error
	Count() (int, error)
	Store(logEntry LogEntry) (uuid.UUID, error)
	RetrieveMany(amount, offset int) ([]LogEntry, error)
	StoreMany(logEntries []LogEntry) ([]uuid.UUID, error)
	Retrieve(id uuid.UUID) (LogEntry, error)
	EntryFilter(filters []AuditLogFilter, amount, offset int) ([]LogEntry, error)
	CountFilter(filters []AuditLogFilter) (int, error)
}

func Backend

func Backend() StorageBackend

func NewInMemoryStorageBackend

func NewInMemoryStorageBackend() StorageBackend

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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