iilyak commented on a change in pull request #1082: Provide info=true and
keys=[] arguments for /_all_dbs
URL: https://github.com/apache/couchdb/pull/1082#discussion_r161304480
##########
File path: src/chttpd/src/chttpd_misc.erl
##########
@@ -103,6 +103,52 @@ maybe_add_csp_headers(Headers, _) ->
Headers.
handle_all_dbs_req(#httpd{method='GET'}=Req) ->
+ Params = lists:flatmap(fun({K, V}) -> parse_all_dbs_param(K, V) end,
+ chttpd:qs(Req)),
+ Args = lists:foldl(fun({K, V}, Arg) -> validate_alldbs_query(K, V, Arg)
+ end, #alldbs_query_args{}, Params),
+ maybe_handle_all_dbs_info(Req, Args#alldbs_query_args.info,
+ Args#alldbs_query_args.keys);
+handle_all_dbs_req(Req) ->
+ send_method_not_allowed(Req, "GET,HEAD").
+
+maybe_handle_all_dbs_info(Req, true, []) ->
+ Params = couch_mrview_http:parse_params(Req, undefined),
+ ShardDbName = config:get("mem3", "shards_db", "_dbs"),
+ Options = [{user_ctx, Req#httpd.user_ctx}],
+ Callback = fun({meta, _}, []) ->
+ {ok, []};
+ ({row, Props}, Acc) ->
+ {ok, [couch_util:get_value(id, Props) | Acc]};
+ (complete, Acc) ->
+ {ok, lists:reverse(Acc)};
+ ({error, Reason}, _Acc) ->
+ {error, Reason}
+ end,
+ {ok, Keys} = fabric:all_docs(ShardDbName, Options, Callback, [], Params),
+ case Keys of
+ [] ->
+ chttpd:send_response(Req, 200, [], <<"[]">>);
+ _ ->
+ maybe_handle_all_dbs_info(Req, true, Keys)
+ end;
+maybe_handle_all_dbs_info(Req, true, Keys) ->
Review comment:
We should have a config which limits the number of databases in Keys to
prevent DOS from malicious users.
----------------------------------------------------------------
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