What the plugin SDK asks of the application around it. Resolving a
template needs two things only the running pipelines know: the tenant's
variables and the methods the tenant's pipelines allow for a request.
Reading a body needs the application's in-memory limit, and work on a
body loaded whole a claim on the application's memory. A call out of the
proxy (Plugin.Provisional.Outbound) goes through the application's forward
side, and a saved output's fingerprint (Plugin.Provisional.SavedOutput) is
keyed with the application's secret. A rate (Plugin.Provisional.Rate)
is counted by the application's counter, and a stamped secret reference
is shown unstamped by the application's rule (Outbound.unstamp/1). A
response cache step's lookup, single flight and fill
(Plugin.Provisional.ResponseCache) are the application's response
cache. The credentials a request is
sent with (Plugin.Provisional.Credentials) and the signed-in caller an
upstream is told of (Plugin.Provisional.Identity) are the
application's. A step's settings checked against the
flow (Plugin.Provisional.Checks) are checked with the application's own
conditions and cache vocabulary. A file a user uploads into a step
(Plugin.Provisional.Files) is kept in the application's storage. A map is written as YAML
(write_yaml/1) by the application's writer. A resource record is read by
its lookup key (resource_get/3) and a resource's action is run
(resource_run/5), both optional callbacks, by the application's
resources. The SDK asks
through this behaviour, so it names no module of the application. The
application names the implementation under :host:
config :alternera_plugin_sdk, :host, MyApp.PluginHostWithout one the SDK uses Alternera.Plugin.Test.Host, the stand-in a
plugin's own tests run on.
Summary
Functions
The methods the tenant's pipelines allow for request, as an Allow header lists them.
The most bytes of a body the tenant's pipelines inspect
(body_inspect_max_bytes), or nil for the application's default. What a
step keeps of a body for an error (Plugin.Error.max_body_bytes/1) is
bounded by it.
Claims room in the application's memory, in the calling process, for
work on input_bytes of bodies and values loaded whole: a JSON path
read of a spooled body (Plugin.Location.read/2), a plugin that runs in
a heap of its own (the Script sandbox). The application claims factor
bytes per byte (Plugin.memory_factor/1; nil for its default) and waits
a moment for room. {:error, :busy, message}
when it has none now, {:error, :size, message} when the claim could
never fit; the claim goes back with release_held_bytes/1.
The step error a refused claim of kind (claim_held_bytes/2) is in
phase, as the application answers its own refusals: its type
(memory_limit for the application's load, body_too_large for a
claim that could never fit), its status and, for a request the
application turned away for its load, when to try again
(retry_after_ms).
The body a spool of open_body_spool/2 holds, its file closed: inline or a file.
Gives a spool of open_body_spool/2 up: its file and its disk claim go.
The most bytes of a body the application holds in memory at once.
The size over which the application holds a body on disk rather than in
memory, and over which a step on it runs in a process of its own under
a heap limit and is metered (Provisional.HeapPeak).
A new spool for a body step that writes the body it leaves a piece at a
time (the Script step run per record), in the calling process: in
memory up to the exchange's spool threshold or 64 KiB, whichever is
lower (what a step keeps there is its own claim's to count), past it in a file of the
step's own beside the held body's, which the application's disk budget
for held bodies claims as it grows. spool is the step's
context.body_spool (nil outside a body phase that spools: there is
none to open, {:error, message}), name a tag unique to the step's
run, which remove_body_spool/2 takes too. The spool is written
(write_body_spool/2) and closed (close_body_spool/1) in the process
that opened it; the body the close gives is the step's to return as
its body, and the application releases it once the exchange no longer
needs it. A spool given up is discard_body_spool/1ed.
Gives back a claim of claim_held_bytes/2.
Removes what is left of a spool open_body_spool(spool, name) opened in
a process that ended before it closed or discarded it (a call killed at
its time or memory limit), with its disk claim.
text with its tenant variable references resolved against scope,
literal applied to the text around them. Raises on a reference that does
not resolve.
The record of resource name ("<package>.<resource>", spec 069) whose
lookup key is key, in tenant_id: {:ok, record}, the record's public
attributes as a map with string keys and JSON-ready values; :not_found
when the tenant has no such record; or {:error, reason}:
:unknown_resource (no such resource in this build), :no_lookup_key
(the resource has no lookup key), :unlicensed (the licence does not
include resources) or the reason a read failed, which the application
logs. An optional callback: a host without it answers {:error, :unsupported}.
Runs the generic action action of resource name ("<package>.<resource>")
in tenant_id with input (argument name to value) on the pipeline's
behalf: {:ok, result}, the result JSON-ready (string keys, decimals and
dates as text), or {:error, reason}: :unknown_resource,
{:unknown_action, open} (no such action open to the API; open lists
the ones that are), :unlicensed, {:invalid, message} (the action
refused the input or failed, the message says why) or the reason a run
failed, which the application logs. Only the generic actions the
resource's expose api: lists run here. With dry_run?: true (a
preview, a dry run) an action that may write, one not in the resource's
read_only_actions, is not run: {:ok, :not_run}. An optional
callback: a host without it answers {:error, :unsupported}.
The id of the tenant whose slug is slug: {:ok, id}; {:error, :not_found} when no tenant has it; {:error, :disabled} when the tenant
is disabled (its hosts do not start); {:error, :not_started} while the
application cannot read its tenants yet (it starts after the plugin
packages), no error; or {:error, reason} when the read failed, which the
application logs. A plugin host entry names its tenant by slug
(Alternera.PluginHosts).
Whether text holds a tenant variable reference, {{NAME}} or {{secret.NAME}}.
Appends bytes to a spool of open_body_spool/2: {:error, :disk_budget, message} when the disk budget has no room for them, {:error, :spool_failed, message} when the file could not be written; either way
the spool is spent and its file gone.
map as YAML text, as the application writes YAML: {:ok, text}, or
{:error, reason} for a map it cannot write. A Jason.OrderedObject
anywhere in map is written with its keys in the order it has.
Callbacks
@callback body_inspect_max_bytes(String.t() | nil) :: pos_integer() | nil
@callback cache_put(String.t(), term(), term(), pos_integer()) :: :ok
@callback call_authorization(map(), String.t(), keyword()) :: {:ok, %{value: String.t(), profile: String.t(), outbound_us: non_neg_integer()}} | {:error, String.t()} | {:error, String.t(), non_neg_integer()}
@callback caller_claims(map(), String.t(), pos_integer()) :: {:ok, map()} | :anonymous
@callback claim_held_bytes(non_neg_integer(), pos_integer() | nil) :: {:ok, term()} | {:error, :busy | :size, String.t()}
@callback claim_refusal(:busy | :size, atom()) :: %{ :type => String.t(), :status => pos_integer(), optional(:retry_after_ms) => pos_integer() }
@callback close_body_spool(term()) :: {:ok, Alternera.Plugin.Body.t()} | {:error, :spool_failed, String.t()}
@callback discard_body_spool(term()) :: :ok
@callback fingerprint_key() :: binary()
@callback in_memory_hold_max_bytes() :: pos_integer()
@callback inline_threshold_bytes() :: non_neg_integer()
@callback max_header_size_bytes() :: pos_integer()
@callback plugin_file_put(String.t(), String.t(), binary(), map(), keyword()) :: {:ok, %{digest: String.t(), size: non_neg_integer(), new?: boolean()}} | {:error, :quota, %{used: non_neg_integer(), limit: non_neg_integer()}} | {:error, String.t()}
@callback plugin_files_reclaim(String.t()) :: {:ok, %{removed: non_neg_integer(), bytes: non_neg_integer()}} | {:error, String.t()}
@callback plugin_files_used(String.t(), String.t()) :: {:ok, non_neg_integer()} | {:error, String.t()}
@callback rate_check(String.t() | nil, String.t(), String.t(), map()) :: :ok | {:refuse, pos_integer()}
@callback read_timeout_ms(String.t() | nil) :: pos_integer()
@callback release_held_bytes(term()) :: :ok
@callback response_cache_give_up(term()) :: :ok
@callback saved_body_max_bytes() :: pos_integer()
@callback script_cache_max_entries(String.t() | nil) :: pos_integer()
Functions
The methods the tenant's pipelines allow for request, as an Allow header lists them.
@spec body_inspect_max_bytes(String.t() | nil) :: pos_integer() | nil
The most bytes of a body the tenant's pipelines inspect
(body_inspect_max_bytes), or nil for the application's default. What a
step keeps of a body for an error (Plugin.Error.max_body_bytes/1) is
bounded by it.
@spec claim_held_bytes(non_neg_integer(), pos_integer() | nil) :: {:ok, term()} | {:error, :busy | :size, String.t()}
Claims room in the application's memory, in the calling process, for
work on input_bytes of bodies and values loaded whole: a JSON path
read of a spooled body (Plugin.Location.read/2), a plugin that runs in
a heap of its own (the Script sandbox). The application claims factor
bytes per byte (Plugin.memory_factor/1; nil for its default) and waits
a moment for room. {:error, :busy, message}
when it has none now, {:error, :size, message} when the claim could
never fit; the claim goes back with release_held_bytes/1.
@spec claim_refusal(:busy | :size, atom()) :: %{ :type => String.t(), :status => pos_integer(), optional(:retry_after_ms) => pos_integer() }
The step error a refused claim of kind (claim_held_bytes/2) is in
phase, as the application answers its own refusals: its type
(memory_limit for the application's load, body_too_large for a
claim that could never fit), its status and, for a request the
application turned away for its load, when to try again
(retry_after_ms).
@spec close_body_spool(term()) :: {:ok, Alternera.Plugin.Body.t()} | {:error, :spool_failed, String.t()}
The body a spool of open_body_spool/2 holds, its file closed: inline or a file.
@spec discard_body_spool(term()) :: :ok
Gives a spool of open_body_spool/2 up: its file and its disk claim go.
@spec in_memory_hold_max_bytes() :: pos_integer()
The most bytes of a body the application holds in memory at once.
@spec inline_threshold_bytes() :: non_neg_integer()
The size over which the application holds a body on disk rather than in
memory, and over which a step on it runs in a process of its own under
a heap limit and is metered (Provisional.HeapPeak).
A new spool for a body step that writes the body it leaves a piece at a
time (the Script step run per record), in the calling process: in
memory up to the exchange's spool threshold or 64 KiB, whichever is
lower (what a step keeps there is its own claim's to count), past it in a file of the
step's own beside the held body's, which the application's disk budget
for held bodies claims as it grows. spool is the step's
context.body_spool (nil outside a body phase that spools: there is
none to open, {:error, message}), name a tag unique to the step's
run, which remove_body_spool/2 takes too. The spool is written
(write_body_spool/2) and closed (close_body_spool/1) in the process
that opened it; the body the close gives is the step's to return as
its body, and the application releases it once the exchange no longer
needs it. A spool given up is discard_body_spool/1ed.
@spec release_held_bytes(term()) :: :ok
Gives back a claim of claim_held_bytes/2.
Removes what is left of a spool open_body_spool(spool, name) opened in
a process that ended before it closed or discarded it (a call killed at
its time or memory limit), with its disk claim.
@spec resolve_tenant_vars!(String.t(), map() | nil, keyword(), (String.t() -> String.t())) :: String.t()
text with its tenant variable references resolved against scope,
literal applied to the text around them. Raises on a reference that does
not resolve.
The record of resource name ("<package>.<resource>", spec 069) whose
lookup key is key, in tenant_id: {:ok, record}, the record's public
attributes as a map with string keys and JSON-ready values; :not_found
when the tenant has no such record; or {:error, reason}:
:unknown_resource (no such resource in this build), :no_lookup_key
(the resource has no lookup key), :unlicensed (the licence does not
include resources) or the reason a read failed, which the application
logs. An optional callback: a host without it answers {:error, :unsupported}.
@spec resource_run(String.t(), String.t(), String.t(), map(), keyword()) :: {:ok, term()} | {:error, term()}
Runs the generic action action of resource name ("<package>.<resource>")
in tenant_id with input (argument name to value) on the pipeline's
behalf: {:ok, result}, the result JSON-ready (string keys, decimals and
dates as text), or {:error, reason}: :unknown_resource,
{:unknown_action, open} (no such action open to the API; open lists
the ones that are), :unlicensed, {:invalid, message} (the action
refused the input or failed, the message says why) or the reason a run
failed, which the application logs. Only the generic actions the
resource's expose api: lists run here. With dry_run?: true (a
preview, a dry run) an action that may write, one not in the resource's
read_only_actions, is not run: {:ok, :not_run}. An optional
callback: a host without it answers {:error, :unsupported}.
@spec tenant_id_for_slug(String.t()) :: {:ok, String.t()} | {:error, :not_found | :disabled | :not_started | term()}
The id of the tenant whose slug is slug: {:ok, id}; {:error, :not_found} when no tenant has it; {:error, :disabled} when the tenant
is disabled (its hosts do not start); {:error, :not_started} while the
application cannot read its tenants yet (it starts after the plugin
packages), no error; or {:error, reason} when the read failed, which the
application logs. A plugin host entry names its tenant by slug
(Alternera.PluginHosts).
Whether text holds a tenant variable reference, {{NAME}} or {{secret.NAME}}.
@spec write_body_spool(term(), iodata()) :: {:ok, term()} | {:error, :disk_budget | :spool_failed, String.t()}
Appends bytes to a spool of open_body_spool/2: {:error, :disk_budget, message} when the disk budget has no room for them, {:error, :spool_failed, message} when the file could not be written; either way
the spool is spent and its file gone.
map as YAML text, as the application writes YAML: {:ok, text}, or
{:error, reason} for a map it cannot write. A Jason.OrderedObject
anywhere in map is written with its keys in the order it has.