AshAuthzed.Adapter behaviour (ash_authzed v0.2.0)

Copy Markdown View Source

Behaviour and unified dispatcher for ReBAC backends (Licet, SpiceDB HTTP, or Memory).

Summary

Functions

Applies a .zed schema text to the backing adapter store.

Checks whether subject has permission on resource, returning {:ok, boolean()} or {:error, Exception.t()}.

Checks whether subject has permission on resource. Returns true if allowed, false otherwise.

Looks up all resource IDs of resource_type on which subject has permission.

Looks up all resource IDs of resource_type on which subject has permission, raising on error.

Applies a list of relationship tuple operations ({:create | :touch | :delete, tuple_string}).

Types

operation()

@type operation() :: {:create | :touch | :delete, String.t()}

Callbacks

apply_schema(schema_text, opts)

@callback apply_schema(schema_text :: String.t(), opts :: keyword()) ::
  :ok | {:ok, term()} | {:error, Exception.t()}

check(resource, permission, subject, opts)

@callback check(
  resource :: String.t(),
  permission :: String.t(),
  subject :: String.t(),
  opts :: keyword()
) ::
  {:ok, boolean()} | {:error, Exception.t()}

lookup_resources(resource_type, permission, subject, opts)

@callback lookup_resources(
  resource_type :: String.t(),
  permission :: String.t(),
  subject :: String.t(),
  opts :: keyword()
) :: {:ok, [String.t()]} | {:error, Exception.t()}

write_tuples(operations, opts)

@callback write_tuples(operations :: [operation()], opts :: keyword()) ::
  {:ok, term()} | {:error, Exception.t()}

Functions

apply_schema(schema_text, opts \\ [])

@spec apply_schema(String.t(), keyword()) ::
  :ok | {:ok, term()} | {:error, Exception.t()}

Applies a .zed schema text to the backing adapter store.

check(resource, permission, subject, opts \\ [])

@spec check(String.t(), String.t() | atom(), String.t(), keyword()) ::
  {:ok, boolean()} | {:error, Exception.t()}

Checks whether subject has permission on resource, returning {:ok, boolean()} or {:error, Exception.t()}.

check?(resource, permission, subject, opts \\ [])

@spec check?(String.t(), String.t() | atom(), String.t(), keyword()) :: boolean()

Checks whether subject has permission on resource. Returns true if allowed, false otherwise.

lookup_resources(resource_type, permission, subject, opts \\ [])

@spec lookup_resources(String.t(), String.t() | atom(), String.t(), keyword()) ::
  {:ok, [String.t()]} | {:error, Exception.t()}

Looks up all resource IDs of resource_type on which subject has permission.

lookup_resources!(resource_type, permission, subject, opts \\ [])

@spec lookup_resources!(String.t(), String.t() | atom(), String.t(), keyword()) :: [
  String.t()
]

Looks up all resource IDs of resource_type on which subject has permission, raising on error.

write_tuples(operations, opts \\ [])

@spec write_tuples([operation()], keyword()) ::
  :ok | {:ok, term()} | {:error, Exception.t()}

Applies a list of relationship tuple operations ({:create | :touch | :delete, tuple_string}).