Spectre.Policy.Resolution (Spectre v0.3.0)

Copy Markdown View Source

Validated policy matcher decision shared by user text and trusted hosts.

source identifies who supplied the evidence; lifecycle semantics depend only on kind and label.

Summary

Functions

Validates and builds an accept or reject resolution.

Returns the compact {kind, label} representation accepted by lifecycle policy commands.

Types

kind()

@type kind() :: :accept | :reject

source()

@type source() :: :user | :host | atom()

t()

@type t() :: %Spectre.Policy.Resolution{
  kind: kind(),
  label: atom(),
  metadata: map(),
  source: source()
}

Functions

new(kind, label, source, metadata \\ %{})

@spec new(kind(), atom(), source(), map()) :: {:ok, t()} | {:error, term()}

Validates and builds an accept or reject resolution.

kind must be :accept or :reject; label and source must be atoms; metadata must be a map. The constructor returns an error tuple instead of raising so host-supplied policy decisions can be rejected without mutating state.

{:ok, resolution} =
  Spectre.Policy.Resolution.new(
    :accept,
    :terms_accepted,
    :host,
    %{actor_id: "admin-1"}
  )

to_tuple(resolution)

@spec to_tuple(t()) :: {kind(), atom()}

Returns the compact {kind, label} representation accepted by lifecycle policy commands.

{:accept, :terms_accepted} =
  Spectre.Policy.Resolution.to_tuple(resolution)