summaryrefslogtreecommitdiff
path: root/src/rabbit_direct.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rabbit_direct.erl')
-rw-r--r--src/rabbit_direct.erl24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/rabbit_direct.erl b/src/rabbit_direct.erl
index 6b829abf..1bb5e5ce 100644
--- a/src/rabbit_direct.erl
+++ b/src/rabbit_direct.erl
@@ -16,7 +16,7 @@
-module(rabbit_direct).
--export([boot/0, start_channel/5]).
+-export([boot/0, connect/3, start_channel/5]).
-include("rabbit.hrl").
@@ -25,6 +25,9 @@
-ifdef(use_specs).
-spec(boot/0 :: () -> 'ok').
+-spec(connect/3 :: (binary(), binary(), binary()) ->
+ {'ok', {rabbit_types:user(),
+ rabbit_framing:amqp_table()}}).
-spec(start_channel/5 :: (rabbit_channel:channel_number(), pid(),
rabbit_types:user(), rabbit_types:vhost(), pid()) ->
{'ok', pid()}).
@@ -44,6 +47,25 @@ boot() ->
transient, infinity, supervisor, [rabbit_client_sup]}),
ok.
+%%----------------------------------------------------------------------------
+
+connect(Username, Password, VHost) ->
+ case lists:keymember(rabbit, 1, application:which_applications()) of
+ true -> ok;
+ false -> exit(broker_not_found_in_vm)
+ end,
+ User = try rabbit_access_control:user_pass_login(Username, Password) of
+ #user{} = User1 -> User1
+ catch
+ exit:#amqp_error{name = access_refused} -> exit(auth_failure)
+ end,
+ try rabbit_access_control:check_vhost_access(User, VHost) of
+ ok -> ok
+ catch
+ exit:#amqp_error{name = access_refused} -> exit(access_refused)
+ end,
+ {ok, {User, rabbit_reader:server_properties()}}.
+
start_channel(Number, ClientChannelPid, User, VHost, Collector) ->
{ok, _, {ChannelPid, _}} =
supervisor2:start_child(