couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [1/2] git commit: updated refs/heads/1867-feature-plugins to 0d848df
Date Fri, 02 Aug 2013 21:11:00 GMT
Updated Branches:
  refs/heads/1867-feature-plugins 42bc6ee4f -> 0d848df86


only install plugins if their CouchDB version matches the target couch


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

Branch: refs/heads/1867-feature-plugins
Commit: 65180c5887bcd4a6120b162794ae14a509123e8d
Parents: 42bc6ee
Author: Jan Lehnardt <jan@apache.org>
Authored: Fri Aug 2 23:09:01 2013 +0200
Committer: Jan Lehnardt <jan@apache.org>
Committed: Fri Aug 2 23:09:01 2013 +0200

----------------------------------------------------------------------
 share/www/plugins.html                        | 10 ++++----
 src/couch_plugins/src/couch_plugins.erl       | 29 ++++++++++++++++------
 src/couch_plugins/src/couch_plugins_httpd.erl | 18 ++++++++------
 3 files changed, 37 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/65180c58/share/www/plugins.html
----------------------------------------------------------------------
diff --git a/share/www/plugins.html b/share/www/plugins.html
index e7ffc26..7f8da53 100644
--- a/share/www/plugins.html
+++ b/share/www/plugins.html
@@ -33,16 +33,16 @@ specific language governing permissions and limitations under the License.
     <div id="content">
       <div class="row">
         <h2>GeoCouch</h2>
-        <p>Version: <strong>couchdb1.2.x_v0.3.0-11-g4ea0bea</strong></p>
+        <p>Version: <strong>couchdb1.2.x_v0.3.0-11-g66e6219</strong></p>
         <p>Author: Volker Mische</p>
         <p>
           Available Erlang Versions:
           <ul>
-            <li>R15B01</li>
+            <li>CouchDB 1.4.0-XXX R15B01</li>
           </ul>
         </p>
         <p>
-          <button href="#" class="install-plugin" data-url="http://people.apache.org/~jan"
data-checksums='{"R15B03":"QVKzRsQGKhSdLkLTdHtgUYtr0wU="}' data-name="geocouch" data-version="couchdb1.2.x_v0.3.0-12-g4ea0bea">Install
GeoCouch Now</button>
+          <button href="#" class="install-plugin" data-url="http://people.apache.org/~jan"
data-checksums='{"1.4.0": {"R15B03":"D5QPhrJTAifM42DXqAj4RxzfEtI="}}' data-name="geocouch"
data-version="couchdb1.2.x_v0.3.0-16-g66e6219">Install GeoCouch Now</button>
         </p>
       </div>
       <div class="row">
@@ -52,11 +52,11 @@ specific language governing permissions and limitations under the License.
         <p>
           Available Erlang Versions:
           <ul>
-            <li>R15B01</li>
+            <li>CouchDB 1.4.0-XXX R15B01</li>
           </ul>
         </p>
         <p>
-          <button href="#" class="install-plugin" data-url="http://people.apache.org/~jan"
data-checksums='{"R15B03":"2IvVuihCBAE4SIN3qgjofx23wJs="}' data-name="couchperuser" data-version="1.0.0">Install
CouchPerUser Now</button>
+          <button href="#" class="install-plugin" data-url="http://people.apache.org/~jan"
data-checksums='{"1.4.0": {"R15B03":"Aj3mjC6M75NA62q5/xkP0tl8Hws="}}' data-name="couchperuser"
data-version="1.0.0">Install CouchPerUser Now</button>
         </p>
       </div>
     </div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/65180c58/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 3463d3d..507f114 100644
--- a/src/couch_plugins/src/couch_plugins.erl
+++ b/src/couch_plugins/src/couch_plugins.erl
@@ -207,18 +207,25 @@ 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
+  CouchDBVersion = couchdb_version(),
+  case proplists:get_value(CouchDBVersion, Checksums) of
   undefined ->
-    ?LOG_ERROR("[couch_plugins] Can't find checksum for OTP Release '~s'", [OTPRelease]),
-    {error, no_checksum};
-  Checksum ->
-    do_verify_checksum(Filename, Checksum)
+    ?LOG_ERROR("[couch_plugins] Can't find checksum for CouchDB Version '~s'", [CouchDBVersion]),
+    {error, no_couchdb_checksum};
+  OTPChecksum ->
+    OTPRelease = erlang:system_info(otp_release),
+    case proplists:get_value(OTPRelease, OTPChecksum) of
+    undefined ->
+      ?LOG_ERROR("[couch_plugins] Can't find checksum for Erlang Version '~s'", [OTPRelease]),
+      {error, no_erlang_checksum};
+    Checksum ->
+      do_verify_checksum(Filename, Checksum)
+    end
   end.
 
 -spec do_verify_checksum(string(), string()) -> ok | {error, string()}.
 do_verify_checksum(Filename, Checksum) ->
-  ?LOG_DEBUG("Filename: ~s", [Filename]),
+  ?LOG_DEBUG("Checking Filename: ~s", [Filename]),
   case file:read_file(Filename) of
   {ok, Data} ->
     ComputedChecksum = binary_to_list(base64:encode(crypto:sha(Data))),
@@ -246,7 +253,8 @@ get_filename(Name, Version) ->
 get_file_slug(Name, Version) ->
   % OtpRelease does not include patch levels like the -1 in R15B03-1
   OTPRelease = erlang:system_info(otp_release),
-  Name ++ "-" ++ Version ++ "-" ++ OTPRelease.
+  CouchDBVersion = couchdb_version(),
+  string:join([Name, Version, OTPRelease, CouchDBVersion], "-").
 
 -spec file_exists(string()) -> boolean().
 file_exists(Filename) ->
@@ -255,6 +263,11 @@ file_exists(Filename) ->
 does_file_exist({error, enoent}) -> false;
 does_file_exist(_Else) -> true.
 
+couchdb_version() ->
+  %% strip git hash from version string
+  [Version|_Rest] = string:tokens(couch_server:get_version(), "+"),
+  Version.
+
 % installing a plugin:
 %  - POST /_plugins -d {plugin-def}
 %  - get plugin definition

http://git-wip-us.apache.org/repos/asf/couchdb/blob/65180c58/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 7a99cd1..d292ec6 100644
--- a/src/couch_plugins/src/couch_plugins_httpd.erl
+++ b/src/couch_plugins/src/couch_plugins_httpd.erl
@@ -25,12 +25,9 @@ handle_req(#httpd{method='POST'}=Req) ->
     Version = binary_to_list(couch_util:get_value(<<"version">>, PluginSpec)),
     Delete = couch_util:get_value(<<"delete">>, PluginSpec),
     {Checksums0} = couch_util:get_value(<<"checksums">>, PluginSpec),
-    Checksums = lists:map(fun({K, V}) ->
-      {binary_to_list(K), binary_to_list(V)}
-    end, Checksums0),
+    Checksums = parse_checksums(Checksums0),
+
     Plugin = {Name, Url, Version, Checksums},
-    ?LOG_DEBUG("~p", [Plugin]),
-    ?LOG_DEBUG("~p", [Delete]),
     case do_install(Delete, Plugin) of
     ok ->
         couch_httpd:send_json(Req, 202, {[{ok, true}]});
@@ -41,7 +38,14 @@ handle_req(#httpd{method='POST'}=Req) ->
 handle_req(Req) ->
     couch_httpd:send_method_not_allowed(Req, "POST").
 
-do_install(false, Plugin)->
+do_install(false, Plugin) ->
     couch_plugins:install(Plugin);
-do_install(true, Plugin)->
+do_install(true, Plugin) ->
     couch_plugins:uninstall(Plugin).
+
+parse_checksums(Checksums) ->
+    lists:map(fun({K, {V}}) ->
+        {binary_to_list(K), parse_checksums(V)};
+      ({K, V}) ->
+         {binary_to_list(K), binary_to_list(V)}
+    end, Checksums).
\ No newline at end of file


Mime
View raw message