Documentation
¶
Index ¶
Constants ¶
const ( OutcomeSuccess = manage.OutcomeSuccess OutcomeFailure = manage.OutcomeFailure )
Outcomes a record can report.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware records every request that can change something.
A middleware rather than a call in each handler, because the requirement is that every mutating action is recorded and a per-handler call would be more difficult to maintain.
func NewMiddleware ¶
func NewMiddleware(sink Sink, clock commoncore.Clock, logger bpcore.Logger) *Middleware
NewMiddleware creates the middleware that records mutating requests.
func (*Middleware) Middleware ¶
func (m *Middleware) Middleware(next http.Handler) http.Handler
type MultiSink ¶
type MultiSink struct {
// contains filtered or unexported fields
}
MultiSink writes each record to every sink it is given.
Every sink is attempted even after one fails, and the failures are reported together. a For example, state backend being unreachable must not also cost the record its line on stdout.
func NewMultiSink ¶
NewMultiSink writes records to all of the given sinks.
type NopSink ¶
type NopSink struct{}
NopSink discards records, for a deployment that has turned the trail off.
type Record ¶
type Record = manage.AuditRecord
Record says who did what, to what, and whether it worked.
Aliased to the state entity rather than converted into it. A record that travels through a sink and a record that is stored are the same record, and a conversion between two copies of the same field list is somewhere a field can be dropped in silence.
type Sink ¶
type Sink interface {
// Write records one action.
//
// The context is for the write itself rather than the request the record describes.
// The request has been answered by the time a record is written, so a sink is given a
// context that outlives it.
Write(ctx context.Context, record *Record) error
io.Closer
}
Sink receives audit records.
Writing a record must not fail a request, the action has already happened by the time the record is written, so refusing the request afterwards would misreport it. A sink reports its error for the caller to log instead.
type StateSink ¶
type StateSink struct {
// contains filtered or unexported fields
}
StateSink persists records through the engine's state backend.
This is the sink that makes the trail queryable. Records land beside the state they describe, the operational endpoints can read them back and a deployment can forward them on or extract them from the backend directly.
func NewStateSink ¶
NewStateSink writes records to the given audit state container.
type WriterSink ¶
type WriterSink struct {
// contains filtered or unexported fields
}
WriterSink writes records as one JSON object per line, which is what every log collector already reads.
func NewStdoutSink ¶
func NewStdoutSink() *WriterSink
NewStdoutSink writes records to stdout.
The record leaves the process immediately, so whatever already collects and rotates the engine's output collects this too. Deliberately not a file: a file on the engine's own host is no further from the state it describes than stdout is, and it brings rotation, pruning and disk headroom along with it.
Written directly rather than through the engine's logger so that a log level cannot discard it. An audit trail that disappears when somebody raises the log level is not one.
func NewWriterSink ¶
func NewWriterSink(writer io.Writer) *WriterSink
NewWriterSink writes records to the given writer.
The destination is the caller's to own and to close: this sink serialises writes to it and nothing more.
func (*WriterSink) Close ¶
func (s *WriterSink) Close() error
Close is a no-op as the destination is the caller's to close. Present so that a sink whose destination does own a handle can be swapped in without changing its callers.
func (*WriterSink) Write ¶
func (s *WriterSink) Write(_ context.Context, record *Record) error
Write appends one record.
Serialised under the lock so that two requests finishing at once cannot interleave within a line, which would leave a collector with two unparseable records rather than two records.