audithook

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package audithook bridges Weave lifecycle events to an audit trail backend.

It defines a local Recorder interface so the package does not import Chronicle directly. Callers inject a RecorderFunc adapter that bridges to Chronicle at wiring time.

Index

Constants

View Source
const (
	SeverityInfo     = "info"
	SeverityWarning  = "warning"
	SeverityCritical = "critical"
)

Severity constants (mirror chronicle/audit).

View Source
const (
	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
)

Outcome constants (mirror chronicle/audit).

View Source
const (
	ActionCollectionCreated  = "weave.collection.created"
	ActionCollectionDeleted  = "weave.collection.deleted"
	ActionIngestStarted      = "weave.ingest.started"
	ActionIngestCompleted    = "weave.ingest.completed"
	ActionIngestFailed       = "weave.ingest.failed"
	ActionRetrievalStarted   = "weave.retrieval.started"
	ActionRetrievalCompleted = "weave.retrieval.completed"
	ActionRetrievalFailed    = "weave.retrieval.failed"
	ActionDocumentDeleted    = "weave.document.deleted"
	ActionReindexStarted     = "weave.reindex.started"
	ActionReindexCompleted   = "weave.reindex.completed"
)

Action constants.

View Source
const (
	ResourceCollection = "collection"
	ResourceDocument   = "document"
	ResourceRetrieval  = "retrieval"
	ResourceReindex    = "reindex"
)

Resource constants.

View Source
const (
	CategoryCollection = "collection"
	CategoryIngestion  = "ingestion"
	CategoryRetrieval  = "retrieval"
	CategoryReindex    = "reindex"
)

Category constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent struct {
	Action     string         `json:"action"`
	Resource   string         `json:"resource"`
	Category   string         `json:"category"`
	ResourceID string         `json:"resource_id,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
	Outcome    string         `json:"outcome"`
	Severity   string         `json:"severity"`
	Reason     string         `json:"reason,omitempty"`
}

AuditEvent is a local representation of an audit event. It mirrors chronicle/audit.Event but avoids a module dependency.

type Extension

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

Extension bridges Weave lifecycle events to an audit trail backend.

func New

func New(r Recorder, opts ...Option) *Extension

New creates an Extension that emits audit events through the provided Recorder.

func (*Extension) Name

func (e *Extension) Name() string

Name implements ext.Extension.

func (*Extension) OnCollectionCreated

func (e *Extension) OnCollectionCreated(ctx context.Context, col *collection.Collection) error

OnCollectionCreated implements ext.CollectionCreated.

func (*Extension) OnCollectionDeleted

func (e *Extension) OnCollectionDeleted(ctx context.Context, colID id.CollectionID) error

OnCollectionDeleted implements ext.CollectionDeleted.

func (*Extension) OnDocumentDeleted

func (e *Extension) OnDocumentDeleted(ctx context.Context, docID id.DocumentID) error

OnDocumentDeleted implements ext.DocumentDeleted.

func (*Extension) OnIngestCompleted

func (e *Extension) OnIngestCompleted(ctx context.Context, colID id.CollectionID, docCount, chunkCount int, elapsed time.Duration) error

OnIngestCompleted implements ext.IngestCompleted.

func (*Extension) OnIngestFailed

func (e *Extension) OnIngestFailed(ctx context.Context, colID id.CollectionID, ingestErr error) error

OnIngestFailed implements ext.IngestFailed.

func (*Extension) OnIngestStarted

func (e *Extension) OnIngestStarted(ctx context.Context, colID id.CollectionID, docs []*document.Document) error

OnIngestStarted implements ext.IngestStarted.

func (*Extension) OnReindexCompleted

func (e *Extension) OnReindexCompleted(ctx context.Context, colID id.CollectionID, elapsed time.Duration) error

OnReindexCompleted implements ext.ReindexCompleted.

func (*Extension) OnReindexStarted

func (e *Extension) OnReindexStarted(ctx context.Context, colID id.CollectionID) error

OnReindexStarted implements ext.ReindexStarted.

func (*Extension) OnRetrievalCompleted

func (e *Extension) OnRetrievalCompleted(ctx context.Context, colID id.CollectionID, resultCount int, elapsed time.Duration) error

OnRetrievalCompleted implements ext.RetrievalCompleted.

func (*Extension) OnRetrievalFailed

func (e *Extension) OnRetrievalFailed(ctx context.Context, colID id.CollectionID, retrievalErr error) error

OnRetrievalFailed implements ext.RetrievalFailed.

func (*Extension) OnRetrievalStarted

func (e *Extension) OnRetrievalStarted(ctx context.Context, colID id.CollectionID, query string) error

OnRetrievalStarted implements ext.RetrievalStarted.

type Option

type Option func(*Extension)

Option configures an audit hook Extension.

func WithActions

func WithActions(actions ...string) Option

WithActions limits the extension to recording only the listed actions. By default all actions are recorded.

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger sets the logger used for internal warnings.

type Recorder

type Recorder interface {
	Record(ctx context.Context, event *AuditEvent) error
}

Recorder is the interface that audit backends must implement. This matches chronicle.Emitter but is defined locally so that the audit_hook package does not import Chronicle directly. Callers inject the concrete *chronicle.Chronicle at wiring time.

type RecorderFunc

type RecorderFunc func(ctx context.Context, event *AuditEvent) error

RecorderFunc is an adapter to use a plain function as a Recorder.

func (RecorderFunc) Record

func (f RecorderFunc) Record(ctx context.Context, event *AuditEvent) error

Record implements Recorder.

Jump to

Keyboard shortcuts

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