audit

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAudit added in v0.13.0

func BuildAudit[T Auditable](ctx context.Context, p *BuildAuditParams[T])

BuildAudit creates an audit log for a workspace build. The audit log is committed upon invocation.

func Empty

func Empty[T Auditable]() T

Empty returns a default value of type T.

func ResourceID added in v0.8.15

func ResourceID[T Auditable](tgt T) uuid.UUID

func ResourceTarget added in v0.8.15

func ResourceTarget[T Auditable](tgt T) string

func ResourceType added in v0.8.15

func ResourceType[T Auditable](tgt T) database.ResourceType

Types

type AdditionalFields added in v0.16.0

type AdditionalFields struct {
	WorkspaceName  string               `json:"workspace_name"`
	BuildNumber    string               `json:"build_number"`
	BuildReason    database.BuildReason `json:"build_reason"`
	WorkspaceOwner string               `json:"workspace_owner"`
}

type Auditable

Auditable is mostly a marker interface. It contains a definitive list of all auditable types. If you want to audit a new type, first define it in AuditableResources, then add it to this interface.

type Auditor added in v0.8.11

type Auditor interface {
	Export(ctx context.Context, alog database.AuditLog) error
	// contains filtered or unexported methods
}

func NewNop added in v0.8.11

func NewNop() Auditor

type BuildAuditParams added in v0.13.0

type BuildAuditParams[T Auditable] struct {
	Audit Auditor
	Log   slog.Logger

	UserID           uuid.UUID
	JobID            uuid.UUID
	Status           int
	Action           database.AuditAction
	AdditionalFields json.RawMessage

	New T
	Old T
}

type Differ added in v0.8.11

type Differ struct {
	DiffFn func(old, new any) Map
}

Differ is used so the enterprise version can implement the diff function in the Auditor feature interface. Only types in the same package as the interface can implement unexported methods.

type Map

type Map map[string]OldNew

Map is a map of changed fields in an audited resource. It maps field names to the old and new value for that field.

func Diff

func Diff[T Auditable](a Auditor, left, right T) Map

Diff compares two auditable resources and produces a Map of the changed values.

type MockAuditor added in v0.8.15

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

func NewMock added in v0.8.15

func NewMock() *MockAuditor

func (*MockAuditor) AuditLogs added in v0.8.15

func (a *MockAuditor) AuditLogs() []database.AuditLog

func (*MockAuditor) Export added in v0.8.15

func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error

type OldNew added in v0.8.11

type OldNew struct {
	Old    any
	New    any
	Secret bool
}

OldNew is a pair of values representing the old value and the new value.

type Request added in v0.8.11

type Request[T Auditable] struct {
	Old T
	New T

	// This optional field can be passed in when the userID cannot be determined from the API Key
	// such as in the case of login, when the audit log is created prior the API Key's existence.
	UserID uuid.UUID

	// This optional field can be passed in if the AuditAction must be overridden
	// such as in the case of new user authentication when the Audit Action is 'register', not 'login'.
	Action database.AuditAction
	// contains filtered or unexported fields
}

func InitRequest added in v0.8.11

func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request[T], func())

InitRequest initializes an audit log for a request. It returns a function that should be deferred, causing the audit log to be committed when the handler returns.

type RequestParams added in v0.8.11

type RequestParams struct {
	Audit Auditor
	Log   slog.Logger

	Request          *http.Request
	Action           database.AuditAction
	AdditionalFields json.RawMessage
}

Jump to

Keyboard shortcuts

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