audit

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Level is the log level at which audit logs are written.
	Level = zerolog.Level(20)
)

Variables

This section is empty.

Functions

func Middleware

func Middleware() func(next http.Handler) http.Handler

Middleware is an HTTP middleware that creates a new audit log entry for the current request and enriches it with information about the request. The log entry is written to the log when the request is complete.

A panic during the request will be recovered and logged as an error in the audit entry. The HTTP status code of the response is also logged in the audit entry; further details may be added by the application.

Types

type Entry

type Entry struct {
	Method           string
	Path             string
	Status           int
	SourceIP         string
	UserAgent        string
	RequestedProfile string
	Authorized       bool
	AuthSubject      string
	AuthIssuer       string
	AuthAudience     []string
	AuthExpirySecs   int64
	Error            string
	Repositories     []string
	Permissions      []string
	ExpirySecs       int64
}

Entry is an audit log entry for the current request.

func Context

func Context(ctx context.Context) (context.Context, *Entry)

Context returns the Entry for the current request, creating one if it does not exist. If the returned context is kept, the returned entry can be further enriched. If not, information written to the entry will be lost.

func Log

func Log(ctx context.Context) *Entry

Get the log entry for the current request. This is safe to use even if the context does not create an entry.

func (*Entry) Begin

func (e *Entry) Begin(r *http.Request)

Begin sets up the audit log entry for the current request with details from the request.

func (*Entry) End

func (e *Entry) End(ctx context.Context) func()

End writes the audit log entry. If the returned func is deferred, any panic will be recovered so the log entry can be written before the panic is re-raised.

func (*Entry) MarshalZerologObject

func (e *Entry) MarshalZerologObject(event *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler. This avoids the need for reflection when logging, at the cost of requiring maintenance when the Entry struct changes.

Jump to

Keyboard shortcuts

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