View Source Noizu.ElixirCore.CallingContext (noizu_core v1.0.28)

callingcontext

CallingContext

Context object used to track a caller's state and permissions along with unique request identifier for tracking requests as they travel through the layers in your application. Useful for log collation, permission checks, access auditing.

application-config-options-and-defaults

Application Config Options and Defaults

  • Include Default IO.inspect formatter defimpl for CallingContext config :noizu_core, inspect_calling_context: true

  • Request ID Extraction Strategy. {m,f} or function2 that accepts (conn, default) and pulls request id (CallingContext.token) from Plug.Conn. config :noizu_core, token_strategy: {Noizu.ElixirCore.CallingContext, :extract_token} - Request Reason Extraction Strategy. {m,f} or function2 that accepts (conn, default) and pulls request reason (CallingContext.reason) from Plug.Conn.config :noizu_core, token_strategy: {Noizu.ElixirCore.CallingContext, :extract_reason}

  • Request Caller Extraction Strategy. {m,f} or function2 that accepts (conn, default) and pulls request Caller (CallingContext.caller) from Plug.Conn config :noizu_core, get_plug_caller: {Noizu.ElixirCore.CallingContext, :extract_caller} - Request Caller's Auth Map Extraction Strategy. {m,f} or function2 that accepts (conn, default) and returns effective permission map ContextCaller.auth.config :noizu_core, acl_strategy: {Noizu.ElixirCore.CallingContext, :default_auth}

  • Default Blank/Empty Request Reason config :noizu_core, default_request_reason: :none

  • Default Restricted User Reference or Object config :noizu_core, default_internal_user: {:ref, Noizu.ElixirCore.CallerEntity, :restricted}

  • Default Internal User Reference or Object config :noizu_core, default_internal_user: {:ref, Noizu.ElixirCore.CallerEntity, :internal}

  • Default System User Reference or Object config :noizu_core, default_system_user: {:ref, Noizu.ElixirCore.CallerEntity, :system}

  • Default Admin User Reference or Object config :noizu_core, default_admin_user: {:ref, Noizu.ElixirCore.CallerEntity, :admin}

  • Default Restricted User Auth Map config :noizu_core, default_internal_auth: %{permissions: %{restricted: true}}

  • Default Internal User Auth Map config :noizu_core, default_internal_auth: %{permissions: %{internal: true}}

  • Default Ssy User Auth Map config :noizu_core, default_system_auth: %{permissions: %{system: true, internal: true}}

  • Default Admin User Auth Map config :noizu_core, default_admin_auth: %{permissions: %{admin: true, system: true, internal: true}}

Link to this section Summary

Functions

Create new calling context with default admin user caller and permissions.

Default logic for grabbing conn's request reason. Using either config noizu_core, extract_reason: {m,f} or included extract_token method.

Default logic for grabbing conn's request id. Using either config noizu_core, token_strategy: {m,f} or included extract_token method.

Extract caller permission level from Plug.Conn. (Currently only depends on default value)

Extract Request Reason from Plug.Conn. Useful for logging purposes/exception handling messaging/tracing on backend.

Extract Request Id Token from Plug.Conn or Generate UUID if non found. Attached to CallingContext to include in log output for log collation.

Get caller effective authentication map.

Get call reason from Plug.Conn

Get call request id from Plug.Conn

Create new calling context with default internal user caller and permissions.

Strip CallingContext meta data from Logger.

Update Logger with CallingContext meta data.

Extract CallingContext meta data for Logger

Generate new Context.Caller by passing in Caller, Auth and options.

Prepare Context object with for given conn. Sets Process meta data by default.

Prepare Context object with given caller/auth and conn request details. Sets Process meta data by default.

Create new calling context with default restricted user caller and permissions.

Create new calling context with default system user caller and permissions.

Link to this section Types

@type t() :: %Noizu.ElixirCore.CallingContext{
  auth: Any,
  caller: tuple(),
  options: Map.t(),
  outer_context: CalingContext.t(),
  reason: String.t(),
  time: DateTime.t() | nil,
  token: String.t(),
  vsn: float()
}

Link to this section Functions

Create new calling context with default admin user caller and permissions.

Link to this function

default_reason(conn, default)

View Source

Default logic for grabbing conn's request reason. Using either config noizu_core, extract_reason: {m,f} or included extract_token method.

Link to this function

default_token(conn, default)

View Source

Default logic for grabbing conn's request id. Using either config noizu_core, token_strategy: {m,f} or included extract_token method.

Link to this function

extract_caller(conn, default)

View Source

Extract caller permission level from Plug.Conn. (Currently only depends on default value)

Link to this function

extract_reason(conn, default)

View Source

Extract Request Reason from Plug.Conn. Useful for logging purposes/exception handling messaging/tracing on backend.

Link to this function

extract_token(conn, default)

View Source

Extract Request Id Token from Plug.Conn or Generate UUID if non found. Attached to CallingContext to include in log output for log collation.

Link to this function

get_auth(caller, options)

View Source

Get caller effective authentication map.

Link to this function

get_caller(conn, default \\ :unauthenticated)

View Source

Get caller from Plug.Conn

Link to this function

get_reason(conn, default \\ nil)

View Source

Get call reason from Plug.Conn

Link to this function

get_token(conn, default \\ :generate)

View Source

Get call request id from Plug.Conn

Create new calling context with default internal user caller and permissions.

Strip CallingContext meta data from Logger.

Update Logger with CallingContext meta data.

Extract CallingContext meta data for Logger

Link to this function

new(caller, auth, options)

View Source

Generate new Context.Caller by passing in Caller, Auth and options.

Link to this function

new_conn(conn, options \\ %{logger_init: true})

View Source

Prepare Context object with for given conn. Sets Process meta data by default.

Link to this function

new_conn(caller, auth, conn, options \\ %{logger_init: true})

View Source

Prepare Context object with given caller/auth and conn request details. Sets Process meta data by default.

Create new calling context with default restricted user caller and permissions.

Link to this function

restricted(conn, options)

View Source

Create new calling context with default system user caller and permissions.