Utilities for parsing ArangoDB endpoints.
iex> Endpoint.new("http://localhost:8529")
%Arangox.Endpoint{addr: {:tcp, "localhost", 8529}, ssl?: false}
iex> Endpoint.new("https://localhost:8529")
%Arangox.Endpoint{addr: {:tcp, "localhost", 8529}, ssl?: true}
iex> Endpoint.new("http://unix:/tmp/arangodb.sock")
%Arangox.Endpoint{addr: {:unix, "/tmp/arangodb.sock"}, ssl?: false}new/1 raises on a malformed endpoint. parse/1 is the same parser
returning {:ok, endpoint} | {:error, message}, and is what
the connection's connect callback uses: a raise from there escapes the
DBConnection callback and gives a supervisor crash loop with no backoff,
where an error tuple gives an orderly retry.
Neither the struct nor any error message either function produces carries the
endpoint's userinfo. The struct never did — parsing consumes the
URI (Uniform Resource Identifier) into :addr and :ssl? and drops
everything else — but the configured binary did reach logs verbatim. Use
redact/1 on any endpoint binary before storing or reporting it.
Summary
Functions
Parses an endpoint and returns an %Arangox.Endpoint{} struct.
Parses an endpoint, returning {:ok, %Arangox.Endpoint{}} or
{:error, message}. Never raises.
Redacts an endpoint binary that could carry a credential.
Types
@type addr() :: {:unix, path :: binary()} | {:tcp, host :: binary(), port :: non_neg_integer()}
Functions
@spec new(Arangox.endpoint()) :: t()
Parses an endpoint and returns an %Arangox.Endpoint{} struct.
Raises ArgumentError when the endpoint is malformed. Use parse/1 on any
path that must not raise.
@spec parse(Arangox.endpoint()) :: {:ok, t()} | {:error, binary()}
Parses an endpoint, returning {:ok, %Arangox.Endpoint{}} or
{:error, message}. Never raises.
@spec redact(Arangox.endpoint() | term()) :: Arangox.endpoint() | term()
Redacts an endpoint binary that could carry a credential.
iex> Arangox.Endpoint.redact("http://root:hunter2@localhost:8529")
"http://[redacted]"
iex> Arangox.Endpoint.redact("http://localhost:8529")
"http://localhost:8529"This is the driver's single redaction point for endpoints.
Arangox.Connection applies it where the configured endpoint is stored,
not only where it is rendered, so the same call covers
Exception.message/1 on an Arangox.Error, inspect/1 on connection state, and the
failed to connect line DBConnection logs on every backoff cycle.
The rule never looks for the userinfo, only for what could hide one: an
endpoint containing an @ anywhere keeps its scheme and loses the rest,
and a value without a scheme separator is replaced entirely. Locating the
userinfo would mean trusting the value to be a well-formed URL, and the
values most likely to carry a password into a log are exactly the typo'd
ones that are not.
An endpoint with a scheme and no @ has no userinfo to lose and passes
through unchanged — which is what keeps host and port visible in error
messages and logs for the ordinary, credential-free configuration. A
redacted value does not parse; nothing that needs the origin may read it
back out of a redacted binary.
Never raises, and returns anything that is not a binary unchanged.