couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [05/23] couchdb-setup git commit: add basic action handling
Date Fri, 07 Nov 2014 14:46:29 GMT
add basic action handling


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/e8c49669
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/e8c49669
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/e8c49669

Branch: refs/heads/master
Commit: e8c49669f950b5461ef79dfefd4767010f92c216
Parents: 58c4948
Author: Jan Lehnardt <jan@apache.org>
Authored: Fri Oct 31 17:06:08 2014 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Fri Oct 31 17:06:08 2014 +0100

----------------------------------------------------------------------
 src/setup_httpd.erl | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/e8c49669/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index f001492..6a4433a 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -15,5 +15,38 @@
 -export([handle_setup_req/1]).
 
 handle_setup_req(Req) ->
-  io:format("~nHandle Req: ~p~n", [Req]).
+    ok = chttpd:verify_is_server_admin(Req),
+    % TBD uncomment after devving
+    %couch_httpd:validate_ctype(Req, "application/json"),
+    Setup = get_body(Req),
+    io:format("~nSetup: ~p~n", [Setup]),
+    Action = binary_to_list(couch_util:get_value(<<"action">>, Setup, <<"missing">>)),
+    case handle_action(Action, Setup) of
+    ok ->
+        chttpd:send_json(Req, 201, {[{ok, true}]});
+    {error, Message} ->
+        couch_httpd:send_error(Req, 400, <<"bad_request">>, Message)
+    end.
 
+
+handle_action("enable_cluster", Setup) ->
+    io:format("~nenable_cluster: ~p~n", [Setup]);
+handle_action("finish_cluster", Setup) ->
+    io:format("~nfinish_cluster: ~p~n", [Setup]);
+handle_action("add_node", Setup) ->
+    io:format("~nadd_node: ~p~n", [Setup]);
+handle_action("remove_node", Setup) ->
+    io:format("~nremove_node: ~p~n", [Setup]);
+handle_action(_, _) ->
+    io:format("~ninvalid_action: ~n", []),
+    {error, <<"Invalid Action'">>}.
+
+
+get_body(Req) ->
+    case catch couch_httpd:json_body_obj(Req) of
+    {Body} ->
+        Body;
+    Else ->
+        io:format("~nBody Fail: ~p~n", [Else]),
+        couch_httpd:send_error(Req, 400, <<"bad_request">>, <<"Missing
JSON body'">>)
+    end.


Mime
View raw message