diff options
author | Jan Lehnardt <jan@apache.org> | 2013-07-31 18:48:19 +0200 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2013-08-02 21:17:03 +0200 |
commit | 30d13d1faf0785f7eb803793e322cfa5940630e2 (patch) | |
tree | 21b06c7016f7912b5987bca88c19e881a16f0484 | |
parent | 8f03635390911888e11d4608fe2306ade9d17796 (diff) | |
download | couchdb-30d13d1faf0785f7eb803793e322cfa5940630e2.tar.gz |
add docs/debug output
-rw-r--r-- | src/couch_plugins/src/couch_plugins.erl | 8 | ||||
-rw-r--r-- | src/couch_plugins/src/couch_plugins_httpd.erl | 25 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl index 0a65bf701..7dd3bd2d3 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}) -> diff --git a/src/couch_plugins/src/couch_plugins_httpd.erl b/src/couch_plugins/src/couch_plugins_httpd.erl index 1e61aa251..6d987aedb 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"). |