Alternera. Plugin. Provisional. Analysis behaviour
(alternera_plugin_sdk v0.9.0)
Copy Markdown
View Source
Provisional: added for Script, and a change to it needs a changelog line but
no new major (docs/USER_PLUGINS_DESIGN.md). The namespace has nothing to do
with the context's :provisional? key.
What a plugin whose settings hold a program tells the proxy about it, from the stored settings and without running it. Every callback is optional. A plugin that exports none is read by its settings alone.
Summary
Types
What a plugin whose step opens the rest of the exchange in Before says
about it (exchange_opener/0); such a step needs an id and a Close in
After that names it (Pipelines.Constructs.Close), and the proxy keeps the two paired
while a pipeline is edited.
A part of the exchange a step can write: the URL (path and query), either side's headers or body, or the pipeline's variables.
What a step reads: :fields lists "req.body", "res.headers", "vars",
"steps.<id>.<output>", "input.<name>", "context.<name>" and "context"
for the whole table. :unknown says it may read anything of the exchange, and
:steps_unknown any step's output.
Callbacks
Whether the plugin's step opens the rest of the exchange in Before and is
closed by a Close in After (opener/0), or nil. Read without settings:
it is the plugin's, not a step's.
The keys of keyed outputs a change of a step's settings from before to
later renames, as {output, old_key, new_key}: what the plugin's own
declaration of its keys says was renamed, never a guess from its text.
The proxy then takes what reads the old key along. [] for none.
Whether the plugin limits its own heap, so the runner does not limit the step's.
The pipelines the step calls by a name its settings show, for cycle checks and callers. A list, even empty, says the step can call pipelines with inputs the proxy cannot read.
Whether a step with these settings makes the response in an Implementation
of own steps: one that answers (Respond, Fail), or one whose To rows write
the response (rows_write_response?/1). An Implementation with no such
step fails no_response, and the editor warns at save. A plugin without
this callback makes no response.
settings with the plugin's own text pointing at new wherever it names
old, a name of kind (:step, :var, :context, :input, :inner
or :store; for a key of a keyed step output, {:step_output, step_id, output} where another step reads it and {:own_output, output} in the
step that gives it, its own text and its declaration): the references
step_reads/1 and stores/1 report, which the proxy cannot rewrite
itself because it does not know the plugin's language. :unknown when the plugin cannot say that
the rewrite moves exactly those references and nothing else; the proxy then
leaves the settings as they are. The proxy rewrites the settings' locations,
conditions and templates itself: a plugin rewrites only what it alone reads.
Whether the step may write a tenant secret into what it writes.
The names under which a step with these settings shares its state with
other steps across the tenant's pipelines, [] for none: two steps of
the plugin that give the same name share one state (a Throttle's turns,
a Circuit breaker's circuit), so a misspelt name silently splits it. The
pipeline editor gathers the names in use and hands a step editor those
of its own plugin (shared_names in Alternera.Plugin.Editor's
props) to suggest. A plugin without this callback shares nothing by name.
What a step with these settings reads, or nil when it holds nothing to analyse.
The named stores the step reads and writes: {reads, writes}.
Whether the step may read tenant variables by a name its settings do not
show as a template (a script's tenant.var(name) with a name built while
it runs): a release's manifest of the variables it needs cannot list
those, and says the step may read others.
What the plugin finds questionable in a step with settings, each a
sentence without the step's name (the proxy prefixes it): a save with
warnings goes through, and the warnings are reported with it. [] for
none.
Every part of the exchange a step with these settings can write, in
direction ("request", "response", "answer", or nil for a step that
may run on either side). A superset is safe: the proxy scans the parts named
for stamped secret references once one is in the exchange, so a part
missed would let a reference reach the recording unresolved. A plugin
without this callback is taken to write every part of its direction and the
variables. target_parts/1 gives the parts the step's To rows write.
Functions
The part a location of kind in (Plugin.Location, as stored: "vars",
"response_body") writes, or nil for one that writes no part (a status,
the error, a step output, an input, a path parameter).
Whether a step's To rows ("targets", and a single "target" beside them)
write the response's body, status or headers, for a produces_response?/1
answer.
The parts a step's To rows ("targets", Plugin.Targets) write, each once,
for a writes/2 answer.
Types
@type opener() :: %{ :close_does => String.t(), :refusal_status => String.t() | nil, :holds => String.t(), optional(:lands) => String.t(), optional(:rank) => non_neg_integer() }
What a plugin whose step opens the rest of the exchange in Before says
about it (exchange_opener/0); such a step needs an id and a Close in
After that names it (Pipelines.Constructs.Close), and the proxy keeps the two paired
while a pipeline is edited.
:close_does: what the Close does at its place, completing "Close <id>: ..." ("gives the turn back");:refusal_status: the status a refusal answers with when the step skips to After instead of failing ("429"), nil for a step that refuses nothing;:holds: one sentence on what the step holds until its Close ("Holds until its Close in After.");:lands: optional, one sentence on what always skips to the Close whatever the step'son_refusal("Hits skip to here: ...");:rank: optional, where the step belongs among the openers in Before: one that stands after an opener of a higher rank is warned about, since what it ends early still goes through the other first. An opener without a rank is not ordered.
@type part() ::
:url
| :request_headers
| :request_body
| :response_headers
| :response_body
| :variables
A part of the exchange a step can write: the URL (path and query), either side's headers or body, or the pipeline's variables.
@type reads() :: %{ :fields => [String.t()], :unknown => boolean(), optional(:steps_unknown) => true }
What a step reads: :fields lists "req.body", "res.headers", "vars",
"steps.<id>.<output>", "input.<name>", "context.<name>" and "context"
for the whole table. :unknown says it may read anything of the exchange, and
:steps_unknown any step's output.
Callbacks
@callback exchange_opener() :: opener() | nil
Whether the plugin's step opens the rest of the exchange in Before and is
closed by a Close in After (opener/0), or nil. Read without settings:
it is the plugin's, not a step's.
@callback output_renames(before :: map(), later :: map()) :: [ {String.t(), String.t(), String.t()} ]
The keys of keyed outputs a change of a step's settings from before to
later renames, as {output, old_key, new_key}: what the plugin's own
declaration of its keys says was renamed, never a guess from its text.
The proxy then takes what reads the old key along. [] for none.
@callback own_heap?() :: boolean()
Whether the plugin limits its own heap, so the runner does not limit the step's.
The pipelines the step calls by a name its settings show, for cycle checks and callers. A list, even empty, says the step can call pipelines with inputs the proxy cannot read.
Whether a step with these settings makes the response in an Implementation
of own steps: one that answers (Respond, Fail), or one whose To rows write
the response (rows_write_response?/1). An Implementation with no such
step fails no_response, and the editor warns at save. A plugin without
this callback makes no response.
@callback rename( settings :: map(), kind :: atom() | tuple(), old :: String.t(), new :: String.t() ) :: {:ok, map()} | :unknown
settings with the plugin's own text pointing at new wherever it names
old, a name of kind (:step, :var, :context, :input, :inner
or :store; for a key of a keyed step output, {:step_output, step_id, output} where another step reads it and {:own_output, output} in the
step that gives it, its own text and its declaration): the references
step_reads/1 and stores/1 report, which the proxy cannot rewrite
itself because it does not know the plugin's language. :unknown when the plugin cannot say that
the rewrite moves exactly those references and nothing else; the proxy then
leaves the settings as they are. The proxy rewrites the settings' locations,
conditions and templates itself: a plugin rewrites only what it alone reads.
Whether the step may write a tenant secret into what it writes.
What a step with these settings reads, or nil when it holds nothing to analyse.
The named stores the step reads and writes: {reads, writes}.
Whether the step may read tenant variables by a name its settings do not
show as a template (a script's tenant.var(name) with a name built while
it runs): a release's manifest of the variables it needs cannot list
those, and says the step may read others.
What the plugin finds questionable in a step with settings, each a
sentence without the step's name (the proxy prefixes it): a save with
warnings goes through, and the warnings are reported with it. [] for
none.
Every part of the exchange a step with these settings can write, in
direction ("request", "response", "answer", or nil for a step that
may run on either side). A superset is safe: the proxy scans the parts named
for stamped secret references once one is in the exchange, so a part
missed would let a reference reach the recording unresolved. A plugin
without this callback is taken to write every part of its direction and the
variables. target_parts/1 gives the parts the step's To rows write.
Functions
The part a location of kind in (Plugin.Location, as stored: "vars",
"response_body") writes, or nil for one that writes no part (a status,
the error, a step output, an input, a path parameter).
@spec parts() :: [part()]
Every part (part/0).
Whether a step's To rows ("targets", and a single "target" beside them)
write the response's body, status or headers, for a produces_response?/1
answer.
The parts a step's To rows ("targets", Plugin.Targets) write, each once,
for a writes/2 answer.