couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [26/49] git commit: updated refs/heads/1867-feature-plugins to d269b53
Date Fri, 02 Aug 2013 20:08:40 GMT
add docs/debug output


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

Branch: refs/heads/1867-feature-plugins
Commit: 30d13d1faf0785f7eb803793e322cfa5940630e2
Parents: 8f03635
Author: Jan Lehnardt <jan@apache.org>
Authored: Wed Jul 31 18:48:19 2013 +0200
Committer: Jan Lehnardt <jan@apache.org>
Committed: Fri Aug 2 21:17:03 2013 +0200

----------------------------------------------------------------------
 src/couch_plugins/src/couch_plugins.erl       |  8 +++----
 src/couch_plugins/src/couch_plugins_httpd.erl | 25 +++++++++++++++++++---
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/30d13d1f/src/couch_plugins/src/couch_plugins.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl
index 0a65bf7..7dd3bd2 100644
--- a/src/couch_plugins/src/couch_plugins.erl
+++ b/src/couch_plugins/src/couch_plugins.erl
@@ -1,13 +1,10 @@
 -module(couch_plugins).
 -include("couch_db.hrl").
-%% Application callbacks
 -export([install/1]).
 
-
 % couch_plugins:install({"geocouch", "http://127.0.0.1:8000", "1.0.0", [{"R15B03", "+XOJP6GSzmuO2qKdnjO+mWckXVs="}]}).
 % couch_plugins:install({"geocouch", "http://people.apache.org/~jan/", "couchdb1.2.x_v0.3.0-11-gd83ba22",
[{"R15B03", "ZetgdHj2bY2w37buulWVf3USOZs="}]}).
 
-
 -define(PLUGIN_DIR, "/tmp/couchdb_plugins").
 
 log(T) -> 
@@ -79,6 +76,7 @@ add_code_path(Name, Version) ->
       Else
   end.
 
+-spec load_plugin(string()) -> ok | {error, atom()}.
 load_plugin(NameList) ->
   Name = list_to_atom(NameList),
   application:load(Name).
@@ -126,6 +124,7 @@ download({Name, _BaseUrl, Version, _Checksums}=Plugin) ->
 
 -spec verify_checksum(string(), list()) -> ok | {error, string()}.
 verify_checksum(Filename, Checksums) ->
+
   OTPRelease = erlang:system_info(otp_release),
   case proplists:get_value(OTPRelease, Checksums) of
   undefined ->
@@ -137,6 +136,7 @@ verify_checksum(Filename, Checksums) ->
 
 -spec do_verify_checksum(string(), string()) -> ok | {error, string()}.
 do_verify_checksum(Filename, Checksum) ->
+  ?LOG_DEBUG("Filename: ~s", [Filename]),
   case file:read_file(Filename) of
   {ok, Data} ->
     ComputedChecksum = binary_to_list(base64:encode(crypto:sha(Data))),
@@ -150,7 +150,7 @@ do_verify_checksum(Filename, Checksum) ->
   end.
 
 
-
+%% utils
 
 -spec get_url(plugin()) -> string().
 get_url({Name, BaseUrl, Version, _Checksums}) ->

http://git-wip-us.apache.org/repos/asf/couchdb/blob/30d13d1f/src/couch_plugins/src/couch_plugins_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins_httpd.erl b/src/couch_plugins/src/couch_plugins_httpd.erl
index 1e61aa2..6d987ae 100644
--- a/src/couch_plugins/src/couch_plugins_httpd.erl
+++ b/src/couch_plugins/src/couch_plugins_httpd.erl
@@ -4,7 +4,26 @@
 
 -include_lib("couch_db.hrl").
 
-handle_req(#httpd{method='PUT'}=Req) ->
-    couch_httpd:send_json(Req, 202, {[{ok, true}]});
+handle_req(#httpd{method='POST'}=Req) ->
+    ok = couch_httpd:verify_is_server_admin(Req),
+    couch_httpd:validate_ctype(Req, "application/json"),
+
+    {PluginSpec} = couch_httpd:json_body_obj(Req),
+  ?LOG_DEBUG("Plugin Spec: ~p", [PluginSpec]),
+    Url = binary_to_list(couch_util:get_value(<<"url">>, PluginSpec)),
+    Name = binary_to_list(couch_util:get_value(<<"name">>, PluginSpec)),
+    Version = binary_to_list(couch_util:get_value(<<"version">>, PluginSpec)),
+    {Checksums0} = couch_util:get_value(<<"checksums">>, PluginSpec),
+    Checksums = lists:map(fun({K, V}) ->
+      {binary_to_list(K), binary_to_list(V)}
+    end, Checksums0),
+
+    case couch_plugins:install({Name, Url, Version, Checksums}}) of
+    ok ->
+        couch_httpd:send_json(Req, 202, {[{ok, true}]});
+    Error ->
+        ?LOG_DEBUG("Plugin Spec: ~p", [PluginSpec]),
+        couch_httpd:send_error(Req, {bad_request, Error})
+    end;
 handle_req(Req) ->
-    couch_httpd:send_method_not_allowed(Req, "PUT").
+    couch_httpd:send_method_not_allowed(Req, "POST").


Mime
View raw message