Skip to content

Commit

Permalink
GET /api/definitions now returns virtual host metadata
Browse files Browse the repository at this point in the history
Closes #10515.
References #11454.
  • Loading branch information
michaelklishin committed Jun 23, 2024
1 parent 86ac886 commit aa466d2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export_name(_Name) -> true.

rw_state() ->
[{users, [name, password_hash, hashing_algorithm, tags, limits]},
{vhosts, [name]},
{vhosts, [name, description, tags, default_queue_type, metadata]},
{permissions, [user, vhost, configure, write, read]},
{topic_permissions, [user, vhost, exchange, write, read]},
{parameters, [vhost, component, name, value]},
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_vhosts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ augment(Basic, ReqData) ->

augmented(ReqData, #context{user = User}) ->
case rabbit_mgmt_util:disable_stats(ReqData) of
false ->
false ->
rabbit_mgmt_db:augment_vhosts(
[rabbit_vhost:info(V) || V <- rabbit_mgmt_util:list_visible_vhosts(User)],
rabbit_mgmt_util:range(ReqData));
Expand All @@ -64,4 +64,4 @@ augmented(ReqData, #context{user = User}) ->
end.

basic() ->
rabbit_vhost:info_all([name]).
rabbit_vhost:info_all([name, description, tags, default_queue_type, metadata]).
44 changes: 43 additions & 1 deletion deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ all_tests() -> [
definitions_server_named_queue_test,
definitions_with_charset_test,
definitions_default_queue_type_test,
definitions_vhost_metadata_test,
long_definitions_test,
long_definitions_multipart_test,
aliveness_test,
Expand Down Expand Up @@ -454,7 +455,6 @@ auth_test(Config) ->
%% NOTE: this one won't have www-authenticate in the response,
%% because user/password are ok, tags are not
test_auth(Config, ?NOT_AUTHORISED, [auth_header("user", "user")]),
WrongAuthResponseHeaders = test_auth(Config, ?NOT_AUTHORISED, [auth_header("guest", "gust")]),
%?assertEqual(true, lists:keymember("www-authenticate", 1, WrongAuthResponseHeaders)),
test_auth(Config, ?OK, [auth_header("guest", "guest")]),
http_delete(Config, "/users/user", {group, '2xx'}),
Expand Down Expand Up @@ -1894,6 +1894,48 @@ defs_default_queue_type_vhost(Config, QueueType) ->
http_delete(Config, "/vhosts/test-vhost", {group, '2xx'}),
ok.

definitions_vhost_metadata_test(Config) ->
register_parameters_and_policy_validator(Config),

VHostName = <<"test-vhost">>,
Desc = <<"Created by definitions_vhost_metadata_test">>,
DQT = <<"quorum">>,
Tags = [<<"one">>, <<"tag-two">>],
Metadata = #{
description => Desc,
default_queue_type => DQT,
tags => Tags
},

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

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

%% Check if vhost definition is correct
VHosts = maps:get(vhosts, Definitions),
{value, VH} = lists:search(fun(VH) ->
maps:get(name, VH) =:= VHostName
end, VHosts),
ct:pal("VHost: ~p", [VH]),
?assertEqual(#{
name => VHostName,
description => Desc,
default_queue_type => DQT,
tags => Tags,
metadata => Metadata
}, VH),

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

%% Remove the test vhost
http_delete(Config, "/vhosts/test-vhost", {group, '2xx'}),
ok.

definitions_default_queue_type_test(Config) ->
defs_default_queue_type_vhost(Config, <<"classic">>),
defs_default_queue_type_vhost(Config, <<"quorum">>).
Expand Down

0 comments on commit aa466d2

Please sign in to comment.