Skip to content

Commit

Permalink
Replace code paths in Mangament UI with rabbit_definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
anhanhnguyen authored and michaelklishin committed Jun 23, 2024
1 parent 2d77bf3 commit ed34acb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
1 change: 0 additions & 1 deletion deps/rabbit/src/rabbit_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ i(cluster_state, VHost) -> vhost_cluster_state(vhost:get_name(VHost));
i(description, VHost) -> vhost:get_description(VHost);
i(tags, VHost) -> vhost:get_tags(VHost);
i(default_queue_type, VHost) -> vhost:get_default_queue_type(VHost);
i(limits, VHost) -> vhost:get_limits(VHost);
i(metadata, VHost) -> vhost:get_metadata(VHost);
i(Item, VHost) ->
rabbit_log:error("Don't know how to compute a virtual host info item '~ts' for virtual host '~tp'", [Item, VHost]),
Expand Down
1 change: 0 additions & 1 deletion deps/rabbit/src/vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ info_keys() ->
description,
tags,
default_queue_type,
limits,
metadata,
tracing,
cluster_state].
Expand Down
46 changes: 12 additions & 34 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(),
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 Expand Up @@ -254,7 +232,7 @@ export_name(_Name) -> true.

rw_state() ->
[{users, [name, password_hash, hashing_algorithm, tags, limits]},
{vhosts, [name, limits, metadata]},
{vhosts, [name]},
{permissions, [user, vhost, configure, write, read]},
{topic_permissions, [user, vhost, exchange, write, read]},
{parameters, [vhost, component, name, value]},
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_wm_vhosts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ augmented(ReqData, #context{user = User}) ->
end.

basic() ->
rabbit_vhost:info_all().
rabbit_vhost:info_all([name]).
2 changes: 1 addition & 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

0 comments on commit ed34acb

Please sign in to comment.