audit

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audit records full request detail (headers and bodies) for later review, off the request path. It is off unless enabled globally or for a key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	AccountID  int64  `json:"accountId"`
	Status     int    `json:"status"`
	Error      string `json:"error,omitempty"`
	DurationMS int64  `json:"durationMs"`
}

type Body

type Body struct {
	Text string `json:"text"`
	// Size is the full length; Text holds only the first MaxBodyKB when Truncated.
	Size      int64 `json:"size"`
	Truncated bool  `json:"truncated"`
}

type Capture

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

Capture collects one request's detail while it runs. All methods are safe on a nil Capture, which is what requests that aren't recorded get.

func (*Capture) Attempt

func (c *Capture) Attempt(accountID int64, status int, msg string, started time.Time)

Attempt notes one try against an upstream account.

func (*Capture) Request

func (c *Capture) Request(body []byte)

Request stores the client's request body.

func (*Capture) Upstream

func (c *Capture) Upstream(resp *http.Response)

Upstream tees the provider's response body as it is read; the last attempt's wins.

func (*Capture) UpstreamRequest

func (c *Capture) UpstreamRequest(body []byte)

UpstreamRequest stores the body sent to the provider; the last attempt's wins.

func (*Capture) Writer

Writer wraps w so what the client receives is recorded too.

type Payload

type Payload struct {
	Method                  string              `json:"method,omitempty"`
	Query                   string              `json:"query,omitempty"`
	RequestHeaders          map[string][]string `json:"requestHeaders,omitempty"`
	ResponseHeaders         map[string][]string `json:"responseHeaders,omitempty"`
	UpstreamStatus          int                 `json:"upstreamStatus,omitempty"`
	UpstreamResponseHeaders map[string][]string `json:"upstreamResponseHeaders,omitempty"`
	Request                 *Body               `json:"request,omitempty"`
	UpstreamRequest         *Body               `json:"upstreamRequest,omitempty"`
	UpstreamResponse        *Body               `json:"upstreamResponse,omitempty"`
	Response                *Body               `json:"response,omitempty"`
}

Payload is the detail stored compressed with each entry.

func Decode

func Decode(raw []byte) (Payload, error)

Decode unpacks a stored payload.

type Recorder

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

Recorder decides which requests to capture and writes finished ones in batches.

func NewRecorder

func NewRecorder(st *store.Store, settings func() Settings) *Recorder

func (*Recorder) Begin

func (r *Recorder) Begin(req *http.Request, keyMode string) *Capture

Begin returns a Capture when this request should be recorded, or nil. keyMode is the key's own setting: "on" or "off" override the global switch.

func (*Recorder) Finish

func (r *Recorder) Finish(c *Capture, ev store.UsageEvent, clientIP string)

Finish queues a finished request; ev carries its outcome.

func (*Recorder) Prune

func (r *Recorder) Prune(ctx context.Context) error

Prune applies the retention limits.

func (*Recorder) Run

func (r *Recorder) Run(ctx context.Context)

Run writes queued entries until ctx ends, then drains what's left.

func (*Recorder) Wait

func (r *Recorder) Wait()

Wait blocks until Run has drained the queue after shutdown.

type Settings

type Settings struct {
	// Enabled records every key that doesn't set its own mode.
	Enabled bool `json:"enabled"`
	// Record is "all", "errors" or "success".
	Record string `json:"record"`
	// SamplePercent records only this share of matching requests.
	SamplePercent int `json:"samplePercent"`
	// Models limits recording to these glob patterns; empty means every model.
	Models []string `json:"models"`

	Request          bool `json:"request"`
	UpstreamRequest  bool `json:"upstreamRequest"`
	UpstreamResponse bool `json:"upstreamResponse"`
	Response         bool `json:"response"`
	Headers          bool `json:"headers"`
	// RedactHeaders are hidden on top of the credentials that always are.
	RedactHeaders []string `json:"redactHeaders"`
	// MaxBodyKB truncates each body; 0 keeps it whole.
	MaxBodyKB int `json:"maxBodyKB"`

	RetentionDays int `json:"retentionDays"`
	MaxEntries    int `json:"maxEntries"`
	MaxStorageMB  int `json:"maxStorageMB"`
}

func DefaultSettings

func DefaultSettings() Settings

func (*Settings) Normalize

func (s *Settings) Normalize()

Jump to

Keyboard shortcuts

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