# `Alternera.Plugin.Provisional.Upstream`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/provisional/upstream.ex#L1)

Provisional: added for plugins that run processes of their own, 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.

A plugin that serves its steps from processes of its own on this node (a
pool of OS processes behind loopback ports, say) claims a host suffix, and
the proxy then treats every name under it as that plugin's:

  * the SSRF guard refuses the names to everyone, a client of either door,
    a reverse site, a Request step, a replay;
  * a call the plugin makes itself (`Plugin.Provisional.Outbound.call/3`
    with `:upstream`) to one of them is dialed where `c:dial/2` says, which
    may be loopback, and gets the TLS options `c:tls/1` gives instead of the
    tenant's verification settings.

The suffix must sit under `.internal`, the top-level domain reserved for
private use, so a plugin can never take a name that resolves on the public
internet. Two installed plugins may not claim the same suffix, or one that
ends with the other's: the proxy refuses to start.

The exemption belongs to the call, not to the name. A forward pipeline may
move a plugin's call to another host; that request is then an ordinary one,
checked by the guard and sent without the call's `:upstream` headers. And a
plugin installed in the proxy can call anything the proxy can: the guard
keeps tenants and their clients away from the plugin's processes, not the
plugin away from the network.

# `dial`

```elixir
@callback dial(host :: String.t(), port :: :inet.port_number()) ::
  {:ok, [:inet.ip_address(), ...]} | {:error, atom()}
```

Where to dial `host` (a name under the suffix) on `port`: the addresses,
tried in order, or an error that fails the call before anything is sent
(`:not_listening` when nothing of the plugin's serves that name and port).
Called on every dial of one of the plugin's calls, so it reads what it
needs from memory.

# `tls`
*optional* 

```elixir
@callback tls(host :: String.t()) :: {:ok, keyword()} | {:error, atom()}
```

The `:ssl` options of a TLS dial to `host`, verification included: the
tenant's settings and the installation's trusted roots do not apply. Without
this callback a call over `https` to the plugin's names fails `:no_tls`.

# `upstream_suffix`

```elixir
@callback upstream_suffix() :: String.t()
```

The suffix the plugin claims, with its leading dot: `".camel.internal"`.
Compared case-insensitively, against the name without a trailing dot.

# `normalize`

```elixir
@spec normalize(String.t()) :: String.t()
```

`host` as the proxy compares it with a suffix: lower case, without a
trailing dot.

# `valid_suffix?`

```elixir
@spec valid_suffix?(term()) :: boolean()
```

Whether `suffix` is one a plugin may claim: starts with a dot, ends with
`.internal`, at least one label before it, each a DNS label of letters,
digits and hyphens, all lower case.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
