couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] chttpd commit: updated refs/heads/master to 1950654
Date Wed, 17 Jun 2015 14:22:44 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 58a987a57 -> 195065434


Revert "Remove _config route on cluster"

This reverts commit 2a583cb0dfcd446ae259b272acd58068079c9b52.


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

Branch: refs/heads/master
Commit: bd1f8ca3a0f24c170487865afc32af3129bc3ad6
Parents: 58a987a
Author: Robert Newson <rnewson@apache.org>
Authored: Wed Jun 17 12:32:16 2015 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jun 17 15:22:27 2015 +0100

----------------------------------------------------------------------
 src/chttpd.erl      |  1 +
 src/chttpd_misc.erl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/bd1f8ca3/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 2dd17cb..5d1f4ee 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -366,6 +366,7 @@ url_handler("favicon.ico") ->   fun chttpd_misc:handle_favicon_req/1;
 url_handler("_utils") ->        fun chttpd_misc:handle_utils_dir_req/1;
 url_handler("_all_dbs") ->      fun chttpd_misc:handle_all_dbs_req/1;
 url_handler("_active_tasks") -> fun chttpd_misc:handle_task_status_req/1;
+url_handler("_config") ->       fun chttpd_misc:handle_config_req/1;
 url_handler("_reload_query_servers") -> fun chttpd_misc:handle_reload_query_servers_req/1;
 url_handler("_replicate") ->    fun chttpd_misc:handle_replicate_req/1;
 url_handler("_uuids") ->        fun chttpd_misc:handle_uuids_req/1;

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/bd1f8ca3/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index f1a45d3..3afa30c 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -14,6 +14,7 @@
 
 -export([
     handle_all_dbs_req/1,
+    handle_config_req/1,
     handle_favicon_req/1,
     handle_favicon_req/2,
     handle_replicate_req/1,
@@ -224,6 +225,58 @@ handle_uuids_req(Req) ->
     couch_httpd_misc_handlers:handle_uuids_req(Req).
 
 
+% Config request handler
+
+
+% GET /_config/
+% GET /_config
+handle_config_req(#httpd{method='GET', path_parts=[_]}=Req) ->
+    Grouped = lists:foldl(fun({{Section, Key}, Value}, Acc) ->
+        case dict:is_key(Section, Acc) of
+        true ->
+            dict:append(Section, {list_to_binary(Key), list_to_binary(Value)}, Acc);
+        false ->
+            dict:store(Section, [{list_to_binary(Key), list_to_binary(Value)}], Acc)
+        end
+    end, dict:new(), config:all()),
+    KVs = dict:fold(fun(Section, Values, Acc) ->
+        [{list_to_binary(Section), {Values}} | Acc]
+    end, [], Grouped),
+    send_json(Req, 200, {KVs});
+% GET /_config/Section
+handle_config_req(#httpd{method='GET', path_parts=[_,Section]}=Req) ->
+    KVs = [{list_to_binary(Key), list_to_binary(Value)}
+            || {Key, Value} <- config:get(Section)],
+    send_json(Req, 200, {KVs});
+% PUT /_config/Section/Key
+% "value"
+handle_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Req) ->
+    Value = chttpd:json_body(Req),
+    Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
+    OldValue = config:get(Section, Key, ""),
+    ok = config:set(Section, Key, ?b2l(Value), Persist),
+    send_json(Req, 200, list_to_binary(OldValue));
+% GET /_config/Section/Key
+handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
+    case config:get(Section, Key, undefined) of
+    undefined ->
+        throw({not_found, unknown_config_value});
+    Value ->
+        send_json(Req, 200, list_to_binary(Value))
+    end;
+% DELETE /_config/Section/Key
+handle_config_req(#httpd{method='DELETE',path_parts=[_,Section,Key]}=Req) ->
+    Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
+    case config:get(Section, Key, undefined) of
+    undefined ->
+        throw({not_found, unknown_config_value});
+    OldValue ->
+        config:delete(Section, Key, Persist),
+        send_json(Req, 200, list_to_binary(OldValue))
+    end;
+handle_config_req(Req) ->
+    send_method_not_allowed(Req, "GET,PUT,DELETE").
+
 % Note: this resource is exposed on the backdoor interface, but it's in chttpd
 % because it's not couch trunk
 handle_system_req(Req) ->


Mime
View raw message