audit

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package audit provides HTTP middleware for audit logging and query handler for audit log access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(auditStore Store, authProvider Auth) func(http.Handler) http.Handler

Middleware creates middleware that logs audit entries after handler completes. This is a convenience function that creates a logger and returns its middleware.

func NoopMiddleware

func NoopMiddleware(next http.Handler) http.Handler

NoopMiddleware returns a pass-through middleware (used when audit is disabled).

Types

type Auth

type Auth interface {
	GetRequestActor(r *http.Request) (actorType, actorName string)
	IsRequestAdmin(r *http.Request) bool
}

Auth defines the interface for auth operations needed by audit.

type Handler

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

Handler handles audit query requests.

func NewHandler

func NewHandler(auditStore Store, authSvc Auth, maxLimit int) *Handler

NewHandler creates a new audit handler.

func (*Handler) HandleQuery

func (h *Handler) HandleQuery(w http.ResponseWriter, r *http.Request)

HandleQuery handles POST /audit/query requests. Requires admin privileges via session cookie or API token with admin flag.

type QueryRequest

type QueryRequest struct {
	Key       string `json:"key,omitempty"`        // prefix match with * suffix
	Actor     string `json:"actor,omitempty"`      // exact match
	ActorType string `json:"actor_type,omitempty"` // user, token, public
	Action    string `json:"action,omitempty"`     // read, create, update, delete
	Result    string `json:"result,omitempty"`     // success, denied, not_found
	From      string `json:"from,omitempty"`       // RFC3339 timestamp
	To        string `json:"to,omitempty"`         // RFC3339 timestamp
	Limit     int    `json:"limit,omitempty"`      // max entries to return
}

QueryRequest represents the JSON request for audit query.

type QueryResponse

type QueryResponse struct {
	Entries []store.AuditEntry `json:"entries"`
	Total   int                `json:"total"`
	Limit   int                `json:"limit"`
}

QueryResponse represents the JSON response for audit query.

type Store

type Store interface {
	LogAudit(ctx context.Context, entry store.AuditEntry) error
	QueryAudit(ctx context.Context, q store.AuditQuery) ([]store.AuditEntry, int, error)
}

Store defines the interface for audit log storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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