From commits-return-34683-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Tue Sep 18 10:27:28 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 762B4180672 for ; Tue, 18 Sep 2018 10:27:27 +0200 (CEST) Received: (qmail 12622 invoked by uid 500); 18 Sep 2018 08:27:21 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 11388 invoked by uid 99); 18 Sep 2018 08:27:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2018 08:27:20 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id C13B682E70; Tue, 18 Sep 2018 08:27:19 +0000 (UTC) Date: Tue, 18 Sep 2018 08:27:35 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 17/22: validate partitioned design docs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: rnewson@apache.org In-Reply-To: <153725923872.26441.12283702123486134413@gitbox.apache.org> References: <153725923872.26441.12283702123486134413@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/user-partitioned-dbs-7 X-Git-Reftype: branch X-Git-Rev: 6d388e08f209fa39b2e2a7f8862ad490743691c4 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180918082719.C13B682E70@gitbox.apache.org> 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 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