You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/09/18 14:00:02 UTC
[couchdb] 14/18: validate partitioned design docs
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 51f7c7fea802481e8f68557bf9e8f60157e1ba0e
Author: Garren Smith <ga...@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