# `Alternera.PluginHosts.Endpoint`
[🔗](https://github.com/10e-ab/alternera-camel/blob/v0.9.0/alternera_plugin_hosts/lib/alternera/plugin_hosts/endpoint.ex#L1)

The address of a plugin host's HTTP call channel, as a plugin host
step writes it into a call's URL:
`<scheme>://<host>.<tenant id><suffix>:<port>/ops/<op>`, where `<host>`
is the configured host's name and `<tenant id>` the id of the tenant it
belongs to (`PluginHosts.key/2`: two tenants' hosts of one name are two
names here, never one upstream), `<suffix>` its kind's
(`.camel.internal`, `.command.internal`: `upstream_suffix/0` of the
kind's plugin, `PluginHosts.Kind`) and `<port>` the loopback
port a ready member announced in its hello (`PluginHosts.Host`).

The kind's plugin claims the suffix (`Plugin.Provisional.Upstream`) and
answers the proxy's questions about a name under it from here: `dial/2`,
`127.0.0.1` when a ready member of that host listens on that port, and
`tls/1`. Everything else is the proxy's (`Alternera.ReservedUpstreams`):
the SSRF guard refuses the names to everyone, and only the step's
own call (`Plugin.Provisional.Outbound` with `upstream:`) is dialed here,
while its target is still the one the step addressed. A client of the
forward door, a Request step, a pipeline that moved a call elsewhere, a
reverse site and a replay all get the refusal, and the allowlist is not
involved, so allowing one host does not open the loopback range to every
tenant.

The port is not the guard against a caller who learns it: each member
requires the random token its start was handed (`ALTERNERA_HOST_TOKEN`) in
`Alternera-Host-Token`. The token is one of the call's upstream headers,
which the forwarder writes into the head as the request leaves for that
member, so no pipeline step reads it and no recording keeps it.

Over HTTPS the certificate is the member's own, minted by its `Host` at
each start for the name above. No public root can vouch for it, and a
tenant's verification settings do not apply: `tls/1` verifies the peer
against exactly the certificates of that host's ready members.

# `dial`

```elixir
@spec dial(module(), String.t(), :inet.port_number()) ::
  {:ok, [:inet.ip_address(), ...]} | {:error, :not_listening}
```

Where to dial `host`, a name under `kind`'s suffix, on `port`: `{:ok,
[{127, 0, 0, 1}]}` when a ready member of the named host listens there,
`{:error, :not_listening}` when none does.

# `host_name`

```elixir
@spec host_name(module(), String.t(), String.t()) :: String.t()
```

The host name a call to the tenant's plugin host `name` of `kind` is addressed to.

# `origin`

```elixir
@spec origin(module(), String.t(), String.t(), :inet.port_number(), String.t()) ::
  String.t()
```

The scheme, host and port of a member of the tenant's host `name`
listening on `port`, with no path.

# `scheme`

```elixir
@spec scheme(atom()) :: String.t()
```

The URL scheme of a member that speaks `protocol`.

# `tls`

```elixir
@spec tls(module(), String.t()) :: {:ok, keyword()} | {:error, :not_listening}
```

The TLS options of a dial to `host`, one of `kind`'s names, a name under the suffix: `{:ok,
opts}` pinned to that host's ready members, `{:error, :not_listening}`
when none has a certificate.

# `token_header`

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

The request header that carries a member's token.

# `upstream`

```elixir
@spec upstream(module(), %{protocol: atom(), token: String.t()}) :: map()
```

The `upstream:` of an outbound call to `member`, a member of one of
`kind`'s hosts (`Plugin.Provisional.Outbound`): its wire, and its token,
which leaves as the request does, never in the call's headers, where a
forward pipeline could read it and the recording keep it.

# `url`

```elixir
@spec url(
  module(),
  String.t(),
  String.t(),
  :inet.port_number(),
  String.t(),
  String.t()
) :: String.t()
```

The URL of operation `op` on a member of the tenant's host `name` listening on `port`.

---

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