rnewson commented on a change in pull request #1482: add partition endpoint for 
views along with validation on which
URL: https://github.com/apache/couchdb/pull/1482#discussion_r206905076
 
 

 ##########
 File path: src/chttpd/src/chttpd_db.erl
 ##########
 @@ -250,20 +251,83 @@ handle_view_cleanup_req(Req, Db) ->
     ok = fabric:cleanup_index_files_all_nodes(Db),
     send_json(Req, 202, {[{ok, true}]}).
 
+
+handle_partition_design_req(#httpd{
+        path_parts=[DbName, <<"_partition">>, PartitionKey, _Design, Name, 
<<"_",_/binary>> = Action | _Rest]
+    }=Req, Db) -> 
+    validate_partition_key(PartitionKey),
+
+    case chttpd:qs_value(Req, "partition") of
+        undefined ->
+            ok;
+        _ ->
+            throw({
+                bad_request,
+                <<"Partition key is not allowed in the query string">>
+            })
+     end,
+
+    case mem3:is_partitioned(DbName) of
+        false -> throw(<<"Database is not partitioned">>);
+        true -> ok
+    end,
+
+    DDoc = get_design_doc(DbName, Name),
+    case check_ddoc_can_use_partitionkey(DDoc) of
+        true ->
+            Handler = chttpd_handlers:partition_design_handler(Action, fun 
bad_action_partition_req/4),
+            Handler(Req, Db, DDoc, PartitionKey);
+        false ->
+            throw({bad_request, <<"Design doc cannot be used on a partitioned 
query">>})
+    end;
+handle_partition_design_req(_Req, _Db) ->
+    throw({bad_request, <<"missing partition key">>}).
+
+
+validate_partition_key(<<"_", _/binary>>) ->
+    throw({bad_request, <<"partition keys must not begin with an 
underscore">>});
+validate_partition_key(<<" ">>) ->
+    throw({bad_request, <<"partition keys cannot begin with a space">>});
+validate_partition_key(_) ->
 
 Review comment:
   this is ad-hoc. there is a function to validate document ids inside couch 
already, we should call that. As per the updated spec, we should call it for 
the partition half _and_ the docid half, each of which has to obey the docid 
rules.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to