Skip to content

Commit a08ed31

Browse files
Merge pull request #12084 from rabbitmq/mergify/bp/v3.13.x/pr-12083
HTTP API: make sure virtual host limit values are returned as a JSON object (backport #12081) (backport #12083)
2 parents e18c587 + 20a2b76 commit a08ed31

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_limits.erl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ limits(ReqData, Context) ->
4747
none ->
4848
User = Context#context.user,
4949
VisibleVhosts = rabbit_mgmt_util:list_visible_vhosts_names(User),
50-
[ [{vhost, VHost}, {value, Value}]
51-
|| {VHost, Value} <- rabbit_vhost_limit:list(),
52-
lists:member(VHost, VisibleVhosts) ];
50+
[
51+
#{
52+
vhost => VHost,
53+
value => rabbit_data_coercion:to_map(Value)
54+
} || {VHost, Value} <- rabbit_vhost_limit:list(), lists:member(VHost, VisibleVhosts)
55+
];
5356
VHost when is_binary(VHost) ->
5457
case rabbit_vhost_limit:list(VHost) of
5558
[] -> [];
56-
Value -> [[{vhost, VHost}, {value, Value}]]
59+
Value -> [
60+
#{
61+
vhost => VHost,
62+
value => rabbit_data_coercion:to_map(Value)
63+
}
64+
]
5765
end
5866
end.
5967
%%--------------------------------------------------------------------

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,13 +3265,14 @@ vhost_limits_list_test(Config) ->
32653265
lists:map(
32663266
fun(#{vhost := VHost, value := Val}) ->
32673267
Param = [ {atom_to_binary(K, utf8),V} || {K,V} <- maps:to_list(Val) ],
3268+
ct:pal("Setting limits of virtual host '~ts' to ~tp", [VHost, Param]),
32683269
ok = rabbit_ct_broker_helpers:set_parameter(Config, 0, VHost, <<"vhost-limits">>, <<"limits">>, Param)
32693270
end,
32703271
Expected),
32713272

3272-
Expected = http_get(Config, "/vhost-limits", ?OK),
3273-
Limits1 = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),
3274-
Limits2 = http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK),
3273+
?assertEqual(lists:usort(Expected), lists:usort(http_get(Config, "/vhost-limits", ?OK))),
3274+
?assertEqual(Limits1, http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK)),
3275+
?assertEqual(Limits2, http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK)),
32753276

32763277
NoVhostUser = <<"no_vhost_user">>,
32773278
rabbit_ct_broker_helpers:add_user(Config, NoVhostUser),

0 commit comments

Comments
 (0)