Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0DFFE18C20 for ; Wed, 17 Jun 2015 14:22:45 +0000 (UTC) Received: (qmail 53696 invoked by uid 500); 17 Jun 2015 14:22:45 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 53602 invoked by uid 500); 17 Jun 2015 14:22:44 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 53495 invoked by uid 99); 17 Jun 2015 14:22:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jun 2015 14:22:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7F281DFF46; Wed, 17 Jun 2015 14:22:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Wed, 17 Jun 2015 14:22:44 -0000 Message-Id: <9f2f4532d7e84938ad60478b10c5a653@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] chttpd commit: updated refs/heads/master to 1950654 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 Authored: Wed Jun 17 12:32:16 2015 +0100 Committer: Robert Newson 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) ->