audit

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 4

README

pkg/middleware/audit

This package emits request-level audit records for state-changing API operations.

Intent

pkg/middleware/audit is the accountability layer that turns normalized request context into audit log events.

It is intentionally selective rather than exhaustive. The goal is to record who changed what, in which scope, and with what result, rather than logging every routine read.

That selectivity is deliberate for two reasons:

  • reduce signal-to-noise for the end user or auditor consuming the logs
  • avoid paying unnecessary logging cost on hot API paths at high request volumes

Its main responsibilities are:

  • log write-like API activity
  • attach actor, component, scope, resource, operation, and result information
  • rely on the normalized authorization context built earlier in the middleware stack

Invariants

  • Audit logging depends on trusted authorization context already being present.
  • The package is focused on mutating operations rather than routine reads.
  • Resource identification is derived from route structure and response metadata rather than custom per-handler audit code.
  • The log record shape is intended to be stable enough for downstream audit processing.

Caveats

  • Global or unscoped calls may be intentionally skipped when the package cannot derive meaningful accountability context.
  • The package depends on route shape and response structure matching the expected API patterns.
  • If upstream middleware fails to populate authorization or route context correctly, audit quality degrades silently.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Subject string `json:"subject"`
}

type Component

type Component struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type Logger

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

func New

func New(application, version string) *Logger

New returns an initialized middleware.

func (*Logger) Middleware added in v1.14.0

func (l *Logger) Middleware(next http.Handler) http.Handler

type Operation

type Operation struct {
	Verb string `json:"verb"`
}

type Resource

type Resource struct {
	Type string `json:"type"`
	ID   string `json:"id,omitempty"`
}

type Result

type Result struct {
	Status int `json:"status"`
}

Jump to

Keyboard shortcuts

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