Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
hash admin passwords, more resilient port parsing
  • Loading branch information
janl committed Nov 13, 2014
1 parent 0a676fc commit 3304add80963e265b80a342f650d4bb526a6c755
Showing 1 changed file with 23 additions and 3 deletions.
@@ -78,8 +78,7 @@ enable_cluster_int(Options, no) ->
{undefined, undefined} ->
ok;
{Username, Password} ->
% TODO check if this gets hashed
config:set("admins", binary_to_list(Username), binary_to_list(Password))
maybe_set_admin(Username, Password)
end,

case NewBindAddress of
@@ -99,6 +98,16 @@ enable_cluster_int(Options, no) ->
io:format("~nEnable Cluster: ~p~n", [Options]).
%cluster_state:set(enabled).

maybe_set_admin(Username, Password) ->
case couch_auth_cache:get_admin(Username) of
nil ->
HashedPassword = couch_passwords:hash_admin_password(Password),
config:set("admins", binary_to_list(Username), binary_to_list(HashedPassword));
_Else ->
ok
end.


finish_cluster() ->
finish_cluster_int(has_cluster_system_dbs()).
finish_cluster_int(ok) ->
@@ -136,7 +145,8 @@ add_node_int(Options, ok) ->
],

Host = proplists:get_value(host, Options),
Port = integer_to_binary(proplists:get_value(port, Options, 5984)),
Port = get_port(proplists:get_value(port, Options, 5984)),

Url = binary_to_list(<<"http://", Host/binary, ":", Port/binary, "/_cluster_setup">>),

case ibrowse:send_req(Url, Headers, post, Body, RequestOptions) of
@@ -148,6 +158,16 @@ add_node_int(Options, ok) ->
Else
end.

get_port(Port) when is_integer(Port) ->
integer_to_binary(Port);
get_port(Port) when is_list(Port) ->
list_to_binary(Port);
get_port(Port) when is_binary(Port) ->
Port;
get_port(Port) ->
{error, <<"invalid type for port">>}.


create_node_doc(Host, Port) ->
{ok, Db} = couch_db:open_int(<<"nodes">>, []),
Name = get_name(Port),

0 comments on commit 3304add

Please sign in to comment.