diff options
author | Michael Schaefermeyer <michael.schaefermeyer@gmail.com> | 2016-08-01 13:21:31 +0200 |
---|---|---|
committer | Michael Schaefermeyer <michael.schaefermeyer@gmail.com> | 2016-08-01 13:21:31 +0200 |
commit | 5b2a832a42eece9cd13c43899298551ee4906878 (patch) | |
tree | 42db1bf4d2c1032776766b7f57794f385951850c /lib/boltex/bolt.ex | |
parent | 31dec1c42b4ae90da2b738ba480308d620b4b9b2 (diff) | |
download | boltex-5b2a832a42eece9cd13c43899298551ee4906878.tar.gz boltex-5b2a832a42eece9cd13c43899298551ee4906878.tar.xz |
Add auth
Diffstat (limited to 'lib/boltex/bolt.ex')
-rw-r--r-- | lib/boltex/bolt.ex | 23 |
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. |