aboutsummaryrefslogtreecommitdiff
path: root/lib/boltex/bolt.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/boltex/bolt.ex')
-rw-r--r--lib/boltex/bolt.ex23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/boltex/bolt.ex b/lib/boltex/bolt.ex
index 2e7f6b5..8bbf3e7 100644
--- a/lib/boltex/bolt.ex
+++ b/lib/boltex/bolt.ex
@@ -48,8 +48,20 @@ defmodule Boltex.Bolt do
@doc """
Initialises the connection.
+
+ Expects a transport module (i.e. `gen_tcp`) and a `Port`. Accepts
+ authorisation params in the form of {username, password}.
+
+ ## Examples
+
+ iex> Boltex.Bolt.init :gen_tcp, port
+ :ok
+
+ iex> Boltex.Bolt.init :gen_tcp, port, {"username", "password"}
+ :ok
"""
- def init(transport, port, params \\ %{}) do
+ def init(transport, port, auth \\ nil) do
+ params = auth_params auth
send_messages transport, port, [{[@user_agent, params], @sig_init}]
case receive_data(transport, port) do
@@ -62,6 +74,15 @@ defmodule Boltex.Bolt do
end
end
+ defp auth_params(nil), do: %{}
+ defp auth_params({username, password}) do
+ %{
+ scheme: "basic",
+ principal: username,
+ credentials: password
+ }
+ end
+
@doc """
Sends a list of messages using the Bolt protocol and PackStream encoding.