Alternera.Resource.Host behaviour (alternera_resource_sdk v0.9.0)

Copy Markdown View Source

What a resource package needs from the proxy at run time, as a behaviour.

A package compiles before the proxy and cannot name its modules, so the policy checks (Alternera.Resource.Checks.*), the version mixin and the cache change ask the host. The proxy's implementation is Alternera.Resources.Host, set with config :alternera_resource_sdk, :host, …; a package's own tests run against Alternera.Resource.Test.Host.

Summary

Types

Whether a check is about reading records or changing them.

Callbacks

The id a version row records for the actor; nil for the system.

Whether the host serves resources now. While it does not, every policy but destroy refuses (Alternera.Resource.Checks.Available).

A record of resource name ("<package id>.<resource id>") was written in the tenant: drop what is cached for key (a lookup key value, the record's primary key when the resource has no lookup key, or :all).

Whether the actor may read (:read) or change (:write) records of the tenant.

Whether the actor is the system or a super admin: every check passes.

Functions

The configured host module.

Types

mode()

@type mode() :: :read | :write

Whether a check is about reading records or changing them.

Callbacks

actor_id(actor)

@callback actor_id(actor :: term()) :: String.t() | nil

The id a version row records for the actor; nil for the system.

available?()

@callback available?() :: boolean()

Whether the host serves resources now. While it does not, every policy but destroy refuses (Alternera.Resource.Checks.Available).

changed(tenant_id, name, key)

@callback changed(tenant_id :: String.t(), name :: String.t(), key :: term()) :: :ok

A record of resource name ("<package id>.<resource id>") was written in the tenant: drop what is cached for key (a lookup key value, the record's primary key when the resource has no lookup key, or :all).

role_allows?(actor, tenant_id, mode)

@callback role_allows?(actor :: term(), tenant_id :: String.t(), mode()) :: boolean()

Whether the actor may read (:read) or change (:write) records of the tenant.

system_actor?(actor)

@callback system_actor?(actor :: term()) :: boolean()

Whether the actor is the system or a super admin: every check passes.

Functions

impl()

@spec impl() :: module()

The configured host module.