jiangphcn commented on a change in pull request #1082: Introduce new _dbs_info
endpoint to get info of a list of databases
URL: https://github.com/apache/couchdb/pull/1082#discussion_r162607275
##########
File path: src/chttpd/src/chttpd_misc.erl
##########
@@ -141,6 +144,38 @@ all_dbs_callback({error, Reason}, #vacc{resp=Resp0}=Acc)
->
{ok, Resp1} = chttpd:send_delayed_error(Resp0, Reason),
{ok, Acc#vacc{resp=Resp1}}.
+handle_dbs_info_req(#httpd{method='POST'}=Req) ->
+ chttpd:validate_ctype(Req, "application/json"),
+ Props = couch_httpd:json_body_obj(Req),
+ Keys = couch_mrview_util:get_view_keys(Props),
+ case Keys of
+ undefined -> throw({bad_request, "`keys` member must exist."});
+ _ -> ok
+ end,
+ MaxNumber = config:get_integer("chttpd",
+ "max_db_number_for_dbs_info_req", ?MAX_DB_NUM_FOR_DBS_INFO),
+ case length(Keys) =< MaxNumber of
+ true -> ok;
+ false -> throw({bad_request, request_keys_too_large})
+ end,
+ {ok, Resp} = chttpd:start_json_response(Req, 200),
+ send_chunk(Resp, "["),
+ lists:foldl(fun(DbName, AccSeparator) ->
+ case catch fabric:get_db_info(DbName) of
+ {ok, Result} ->
+ Json = ?JSON_ENCODE({[{key, DbName}, {info, {Result}}]}),
+ send_chunk(Resp, AccSeparator ++ Json);
+ _ ->
Review comment:
I performed below test
1. create two users: one is admin (`foo/bar`) and another is normal user
(`normal_user/member`).
```
curl -X POST http://localhost:15984/_users -H "Accept:
application/json" -H "Content-Type: application/json" -d @member.json
{"ok":true,"id":"org.couchdb.user:normal_user","rev":"1-b39703a91aa01702c53d0297e33bb5f9"}
```
2. create one database (`db1-for-foo`) using admin user (`foo/bar`).
```
curl -u foo:bar http://localhost:15984/db1-for-foo -X PUT
{"ok":true}
```
3. use normal user (`normal_user/member`) to check db1-for-foo, and can get
information of this database.
```
curl -u normal_user:member http://localhost:15984/db1-for-foo
{"db_name":"db1-for-foo","update_seq":"0-g1AAAAFDeJzLYWBg4MhgTmHgz8tPSTV0MDQy1zMAQsMcoARTIkOS_P___7MSGXAqSVIAkkn2hFQ5gFTFE1KVAFJVT0BVHguQZGgAUkCF8wmrXABRuZ-wygMQlfcJq3wAUQlyZxYAHlFWdg","sizes":{"file":33936,"external":0,"active":0},"purge_seq":0,"other":{"data_size":0},"doc_del_count":0,"doc_count":0,"disk_size":33936,"disk_format_version":6,"data_size":0,"compact_running":false,"cluster":{"q":8,"n":3,"w":2,"r":2},"instance_start_time":"0"}
```
4. use normal user to check `_all_dbs`, and get list with db1-for-foo
```
curl -u normal_user:member http://localhost:15984/_all_dbs
["_global_changes","_replicator","_users","db1-for-foo"]
```
Following above behavior, I make `_dbs_info` to be visible in couchdb.
If there is need to restrict access to `_dbs_info`, we will add logic in
upper level.
----------------------------------------------------------------
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