couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [couchdb] 17/22: validate partitioned design docs
Date Tue, 18 Sep 2018 08:27:35 GMT
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-7
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6d388e08f209fa39b2e2a7f8862ad490743691c4
Author: Garren Smith <garren.smith@gmail.com>
AuthorDate: Wed Sep 5 11:55:13 2018 +0200

    validate partitioned design docs
---
 src/couch_mrview/src/couch_mrview.erl | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index 1b1a06b..32e4b39 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -175,16 +175,44 @@ join([H|T], Sep, Acc) ->
     join(T, Sep, [Sep, H | Acc]).
 
 
+validate_partitioned_ddoc(#doc{} = DDoc) ->
+    {DDocProps} = DDoc#doc.body,
+    Banned = [
+        <<"shows">>,
+        <<"rewrites">>,
+        <<"lists">>,
+        <<"updates">>,
+        <<"filters">>,
+        <<"validate_doc_update">>
+        ],
+    validate_partitioned_ddoc(DDocProps, Banned).
+
+
+validate_partitioned_ddoc([], _Banned) ->
+    ok;
+validate_partitioned_ddoc([{Key, _Value} | Rest], Banned) ->
+    case lists:member(Key, Banned) of
+        true ->
+            Msg = [<<"`">>, Key, <<"` cannot be used in a partitioned design
doc">>],
+            throw({invalid_design_doc, ?l2b(Msg)});
+        false ->
+            validate_partitioned_ddoc(Rest, Banned)
+    end.
+
+
 validate(DbName,  DDoc) ->
     ok = validate_ddoc_fields(DDoc#doc.body),
     DbPartitioned = mem3:is_partitioned(DbName),
     DDocPartitioned = get_partitioned_opt(DDoc#doc.body, DbPartitioned),
-    if
-        not DbPartitioned andalso DDocPartitioned ->
+
+    case {DbPartitioned, DDocPartitioned} of
+        {true, true} ->
+            validate_partitioned_ddoc(DDoc);
+        {false, true} ->
             throw({invalid_design_doc,
                 <<"partitioned option cannot be true in a "
                   "non-partitioned database.">>});
-        true ->
+        {_, _} -> 
             ok
     end,
     GetName = fun


Mime
View raw message