Documentation
¶
Overview ¶
Package audit writes the immutable audit log: who did what to which target, before and after, from where, and whether it was allowed.
Index ¶
- Constants
- Variables
- func In(t i18n.Text, l i18n.Lang, english string) string
- func KeepParts(meta map[string]any, key string, parts ...any) map[string]any
- func KeepReason(meta map[string]any, t i18n.Text) (string, map[string]any)
- func KeepSummary(meta map[string]any, parts ...any) map[string]any
- func KeepText(meta map[string]any, key string, t i18n.Text) map[string]any
- func LanguageArg(code string) map[string]any
- func PrincipalFrom(ctx context.Context) *authz.Principal
- func Render(t i18n.Text, l i18n.Lang) string
- func WithPrincipal(ctx context.Context, p *authz.Principal) context.Context
- func WithRequest(ctx context.Context, r Request) context.Context
- type Actor
- type Event
- type Kept
- type Logger
- type Request
Constants ¶
const ( Allowed = "allowed" Denied = "denied" Failed = "error" )
Result of an audited action.
const SummaryPartsKey = "summary_parts"
SummaryPartsKey holds a summary made of facts joined with " · " (kept messages and plain values), under TextsKey.
const TextsKey = "i18n"
TextsKey is the metadata member that holds an entry's kept lines.
Variables ¶
var LanguageName func(l i18n.Lang, code string) string
LanguageName names a content language's code in a reader's language, as a label ("Spanish", "Tiếng Tây Ban Nha"): internal/languages' NameIn, set by the packages that keep languages (LanguageArg). Without it a language reads as its code.
Functions ¶
func In ¶
In writes a kept line in a language, or returns english when it wasn't kept (or its message is gone).
func KeepParts ¶
KeepParts sets a line of an entry's metadata ("summary", "outcome") made of facts joined with " · ", like KeepSummary: the English under key, the parts under TextsKey as key_parts.
func KeepReason ¶
KeepReason keeps the reason of an entry that ReputeCast wrote itself (a group mapping's "no longer in Okta group “Marketing”") and returns its English, for Event.Reason; the message goes to the metadata under TextsKey. Reasons people type are kept as they typed them.
func KeepSummary ¶
KeepSummary sets an entry's summary made of facts joined with " · ": each part is a kept message (i18n.Text) or a plain value (string) that reads the same in every language, such as a name or a permission key.
func KeepText ¶
KeepText sets a line of an entry's metadata ("summary", "detail"…): its English under key, and the message under TextsKey.
func LanguageArg ¶
LanguageArg is a content language as an argument of a kept line: kept as its code and named when the line is read, in the reader's language.
func PrincipalFrom ¶
PrincipalFrom returns the acting principal stored in ctx, if any.
func Render ¶
Render writes a kept message in a language, its kept messages among its arguments first (without their final period), its lists as the language writes a list and its languages by their names. It returns "" when a message isn't known, like i18n.Text.In.
func WithPrincipal ¶
WithPrincipal stores the acting principal in ctx.
Types ¶
type Event ¶
type Event struct {
WorkspaceID *uuid.UUID
Action string // dotted verb: "routing.update", "apikey.create", "auth.sign_in"
TargetType string
TargetID string
TargetName string
Result string
Reason string
Before any
After any
Metadata map[string]any
// Actor overrides the actor taken from the context (system jobs, sign-in).
Actor *Actor
}
Event is one audit entry. Use Log to write it.
type Kept ¶
type Kept struct {
Summary i18n.Text `json:"summary"`
SummaryParts []json.RawMessage `json:"summary_parts"`
Detail i18n.Text `json:"detail"`
What i18n.Text `json:"what"`
Target i18n.Text `json:"target"`
Note i18n.Text `json:"note"`
Outcome i18n.Text `json:"outcome"`
OutcomeParts []json.RawMessage `json:"outcome_parts"`
Reason i18n.Text `json:"reason"`
}
Kept are an entry's kept lines, read from its metadata.