Ankusa.Audit.Context (ankusa v0.7.0)

Copy Markdown View Source

Who is making a change, from where, and under which request: the part of an audit row (Ankusa.Audit) that the mutation itself does not know.

Mounted as a plug behind Ankusa.Admin.Auth on the admin and route-management APIs, it builds the context from the authenticated Ankusa.Principal (actor), Ankusa.Net.ClientIP (remote_ip, with routes.trusted_proxies deciding whose X-Forwarded-For is believed) and the caller's X-Request-Id (a fresh UUIDv7 when absent or not a plain token), and answers the request id in the x-request-id response header. A change made from code, with no request, is system/0.

Summary

Functions

The context carried by conn, system/0 when the plug did not run.

The context in opts[:audit], system/0 when the caller gave none.

The context of a change that no request made.

Types

t()

@type t() :: %Ankusa.Audit.Context{
  actor: String.t(),
  remote_ip: String.t() | nil,
  request_id: String.t() | nil
}

Functions

from_conn(conn)

@spec from_conn(Plug.Conn.t()) :: t()

The context carried by conn, system/0 when the plug did not run.

from_opts(opts)

@spec from_opts(keyword()) :: t()

The context in opts[:audit], system/0 when the caller gave none.

system()

@spec system() :: t()

The context of a change that no request made.