mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
support riak authentication
This commit is contained in:
parent
ef02053a9d
commit
2d103b4ae1
@ -28,7 +28,7 @@
|
|||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/4, get_proc/1, make_bucket/1, put/2, put/3,
|
-export([start_link/5, get_proc/1, make_bucket/1, put/2, put/3,
|
||||||
get/2, get/3, get_by_index/4, delete/1, delete/2,
|
get/2, get/3, get_by_index/4, delete/1, delete/2,
|
||||||
count_by_index/3, get_by_index_range/5,
|
count_by_index/3, get_by_index_range/5,
|
||||||
get_keys/1, get_keys_by_index/3, is_connected/0,
|
get_keys/1, get_keys_by_index/3, is_connected/0,
|
||||||
@ -68,8 +68,8 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%% @private
|
%% @private
|
||||||
start_link(Num, Server, Port, _StartInterval) ->
|
start_link(Num, Server, Port, _StartInterval, Options) ->
|
||||||
gen_server:start_link({local, get_proc(Num)}, ?MODULE, [Server, Port], []).
|
gen_server:start_link({local, get_proc(Num)}, ?MODULE, [Server, Port, Options], []).
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
is_connected() ->
|
is_connected() ->
|
||||||
@ -429,10 +429,8 @@ map_key(Obj, _, _) ->
|
|||||||
%%% gen_server API
|
%%% gen_server API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%% @private
|
%% @private
|
||||||
init([Server, Port]) ->
|
init([Server, Port, Options]) ->
|
||||||
case riakc_pb_socket:start(
|
case riakc_pb_socket:start(Server, Port, Options) of
|
||||||
Server, Port,
|
|
||||||
[auto_reconnect]) of
|
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
erlang:monitor(process, Pid),
|
erlang:monitor(process, Pid),
|
||||||
{ok, #state{pid = Pid}};
|
{ok, #state{pid = Pid}};
|
||||||
|
@ -103,12 +103,26 @@ init([]) ->
|
|||||||
StartInterval = get_start_interval(),
|
StartInterval = get_start_interval(),
|
||||||
Server = get_riak_server(),
|
Server = get_riak_server(),
|
||||||
Port = get_riak_port(),
|
Port = get_riak_port(),
|
||||||
|
CACertFile = get_riak_cacertfile(),
|
||||||
|
Username = get_riak_username(),
|
||||||
|
Password = get_riak_password(),
|
||||||
|
Options = lists:filter(
|
||||||
|
fun(X) -> X /= nil end,
|
||||||
|
[auto_reconnect,
|
||||||
|
if CACertFile /= nil -> {cacertfile ,CACertFile};
|
||||||
|
true -> nil
|
||||||
|
end,
|
||||||
|
if (Username /= nil) and (Password /= nil) ->
|
||||||
|
{credentials, Username, Password};
|
||||||
|
true -> nil
|
||||||
|
end
|
||||||
|
]),
|
||||||
{ok, {{one_for_one, PoolSize*10, 1},
|
{ok, {{one_for_one, PoolSize*10, 1},
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(I) ->
|
fun(I) ->
|
||||||
{ejabberd_riak:get_proc(I),
|
{ejabberd_riak:get_proc(I),
|
||||||
{ejabberd_riak, start_link,
|
{ejabberd_riak, start_link,
|
||||||
[I, Server, Port, StartInterval*1000]},
|
[I, Server, Port, StartInterval*1000, Options]},
|
||||||
transient, 2000, worker, [?MODULE]}
|
transient, 2000, worker, [?MODULE]}
|
||||||
end, lists:seq(1, PoolSize))}}.
|
end, lists:seq(1, PoolSize))}}.
|
||||||
|
|
||||||
@ -131,6 +145,27 @@ get_riak_server() ->
|
|||||||
binary_to_list(iolist_to_binary(S))
|
binary_to_list(iolist_to_binary(S))
|
||||||
end, ?DEFAULT_RIAK_HOST).
|
end, ?DEFAULT_RIAK_HOST).
|
||||||
|
|
||||||
|
get_riak_cacertfile() ->
|
||||||
|
ejabberd_config:get_option(
|
||||||
|
riak_cacertfile,
|
||||||
|
fun(S) ->
|
||||||
|
binary_to_list(iolist_to_binary(S))
|
||||||
|
end, nil).
|
||||||
|
|
||||||
|
get_riak_username() ->
|
||||||
|
ejabberd_config:get_option(
|
||||||
|
riak_username,
|
||||||
|
fun(S) ->
|
||||||
|
binary_to_list(iolist_to_binary(S))
|
||||||
|
end, nil).
|
||||||
|
|
||||||
|
get_riak_password() ->
|
||||||
|
ejabberd_config:get_option(
|
||||||
|
riak_password,
|
||||||
|
fun(S) ->
|
||||||
|
binary_to_list(iolist_to_binary(S))
|
||||||
|
end, nil).
|
||||||
|
|
||||||
get_riak_port() ->
|
get_riak_port() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
riak_port,
|
riak_port,
|
||||||
@ -162,6 +197,9 @@ opt_type(riak_port) -> fun (_) -> true end;
|
|||||||
opt_type(riak_server) -> fun (_) -> true end;
|
opt_type(riak_server) -> fun (_) -> true end;
|
||||||
opt_type(riak_start_interval) ->
|
opt_type(riak_start_interval) ->
|
||||||
fun (N) when is_integer(N), N >= 1 -> N end;
|
fun (N) when is_integer(N), N >= 1 -> N end;
|
||||||
|
opt_type(riak_cacertfile) -> fun iolist_to_binary/1;
|
||||||
|
opt_type(riak_username) -> fun iolist_to_binary/1;
|
||||||
|
opt_type(riak_password) -> fun iolist_to_binary/1;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[modules, riak_pool_size, riak_port, riak_server,
|
[modules, riak_pool_size, riak_port, riak_server,
|
||||||
riak_start_interval].
|
riak_start_interval, riak_cacertfile, riak_username, riak_password].
|
||||||
|
Loading…
Reference in New Issue
Block a user