Skip to content

core.audit

Overview

An explicit action context for audited writes that happen outside a request.

audited_action

Group every audited write inside this block under one action.

Request traffic takes its context from history middleware. A management command, a background task, or a nested service operation has no request, so it names its own action here. Writes outside any context still record events; they just carry no identity associating them with the other writes of the same operation.

kind says what sort of source the action came from. The middleware records request, VDQ tasks record task, and a management command should pass command. A block that names no kind keeps the kind of the action it runs inside, so a service operation called from a request stays a request action; at the top level it defaults to system. The history API publishes the kind, so a project that adds one should expect clients to render it as an unrecognized value.

Nesting follows pghistory: an inner block adds its metadata to the outer action, and the outer action keeps that metadata until it exits. Only the outermost block clears the action when it ends, because an inner one leaving must not take the action its caller is still writing under.

Signature

audited_action(action, kind, metadata)

Parameters

NameTypeRequiredDescription
actionyes
kindyes
metadatayes

Source

server/vueda/core/audit.py:16

current_action_metadata

Return the metadata of the action currently open, or an empty mapping outside one.

History middleware records the acting user on a request's action, so this is where code holding no user of its own can find who is acting.

pghistory keeps the open action in a thread-local and exposes no reader for it. This is the one place that reaches for it, and the one place to change if pghistory grows a supported one.

Signature

current_action_metadata()

Source

server/vueda/core/audit.py:49

Source

server/vueda/core/audit.py

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2