Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata for vhosts in global definitions exported via UI #11454

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_definitions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,18 @@ to_json(ReqData, Context) ->
end.

all_definitions(ReqData, Context) ->
Xs = [X || X <- rabbit_mgmt_wm_exchanges:basic(ReqData),
export_exchange(X)],
Qs = [Q || Q <- rabbit_mgmt_wm_queues:basic(ReqData),
export_queue(Q)],
QNames = [{pget(name, Q), pget(vhost, Q)} || Q <- Qs],
Bs = [B || B <- rabbit_mgmt_wm_bindings:basic(ReqData),
export_binding(B, QNames)],
Vsn = rabbit:base_product_version(),
ProductName = rabbit:product_name(),
ProductVersion = rabbit:product_version(),
rabbit_mgmt_util:reply(
[{rabbit_version, rabbit_data_coercion:to_binary(Vsn)},
{rabbitmq_version, rabbit_data_coercion:to_binary(Vsn)},
{product_name, rabbit_data_coercion:to_binary(ProductName)},
{product_version, rabbit_data_coercion:to_binary(ProductVersion)}] ++
filter(
[{users, rabbit_mgmt_wm_users:users(all)},
{vhosts, rabbit_mgmt_wm_vhosts:basic()},
{permissions, rabbit_mgmt_wm_permissions:permissions()},
{topic_permissions, rabbit_mgmt_wm_topic_permissions:topic_permissions()},
{parameters, rabbit_mgmt_wm_parameters:basic(ReqData)},
{global_parameters, rabbit_mgmt_wm_global_parameters:basic()},
{policies, rabbit_mgmt_wm_policies:basic(ReqData)},
{queues, Qs},
{exchanges, Xs},
{bindings, Bs}]),
case rabbit_mgmt_util:qs_val(<<"download">>, ReqData) of
undefined -> ReqData;
Filename -> rabbit_mgmt_util:set_resp_header(
<<"Content-Disposition">>,
"attachment; filename=" ++
binary_to_list(Filename), ReqData)
end,
Context).
rabbit_definitions:all_definitions(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can return keys that the HTTP API cannot serialize to JSON as is.

Which is why this filtering exists in the same module:

rw_state() ->
    [{users,              [name, password_hash, hashing_algorithm, tags, limits]},
     {vhosts,             [name]},
     {permissions,        [user, vhost, configure, write, read]},
     {topic_permissions,  [user, vhost, exchange, write, read]},
     {parameters,         [vhost, component, name, value]},
     {global_parameters,  [name, value]},
     {policies,           [vhost, name, pattern, definition, priority, 'apply-to']},
     {queues,             [name, vhost, durable, auto_delete, arguments]},
     {exchanges,          [name, vhost, type, durable, auto_delete, internal,
                           arguments]},
     {bindings,           [source, vhost, destination, destination_type, routing_key,
                           arguments]}].

filter(Items) ->
    [filter_items(N, V, proplists:get_value(N, rw_state())) || {N, V} <- Items].

case rabbit_mgmt_util:qs_val(<<"download">>, ReqData) of
undefined ->
ReqData;
Filename ->
rabbit_mgmt_util:set_resp_header(<<"Content-Disposition">>,
"attachment; filename="
++ binary_to_list(Filename),
ReqData)
end,
Context).

accept_json(ReqData0, Context) ->
case rabbit_mgmt_util:read_complete_body(ReqData0) of
Expand Down
18 changes: 17 additions & 1 deletion deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ definitions_test(Config) ->
#{vhost => vhost,
component => <<"test">>,
name => <<"good">>,
value => <<"ignore">>}),
value => #{a => <<"b">>}}),
defs(Config, global_parameters, "/global-parameters/good", put,
#{name => <<"good">>,
value => #{a => <<"b">>}}),
Expand Down Expand Up @@ -1878,6 +1878,22 @@ defs_default_queue_type_vhost(Config, QueueType) ->

%% Create a test vhost
http_put(Config, "/vhosts/test-vhost", #{default_queue_type => QueueType}, {group, '2xx'}),

Args = #{name => <<"test-vhost">>,
metadata => #{description => <<>>,
default_queue_type => QueueType,
tags => []},
limits => []},

%% Get the definitions
Definitions = http_get(Config, "/definitions", ?OK),

%% Check if vhost definition is correct
true = lists:any(fun(I) -> test_item(Args, I) end, maps:get(vhosts, Definitions)),

%% Post the definitions back
http_post(Config, "/definitions", Definitions, {group, '2xx'}),

PermArgs = [{configure, <<".*">>}, {write, <<".*">>}, {read, <<".*">>}],
http_put(Config, "/permissions/test-vhost/guest", PermArgs, {group, '2xx'}),

Expand Down
Loading