core.audit
Overview
An explicit action context for audited writes that happen outside a request.
action_is_open
Return whether an action is open, so a write made now joins it.
An operation that names its own action only when nothing else has opened one checks this first. Inside an open action it runs unchanged and keeps that action's name.
Signature
action_is_open()
Source
server/vueda/core/audit.py:59
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| action | yes | |||
| kind | no | None | ||
| metadata | no |
Source
server/vueda/core/audit.py:17
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.
Signature
current_action_metadata()
Source
server/vueda/core/audit.py:68
Source
server/vueda/core/audit.py