Skip to content

Commit 687d5f9

Browse files
michaelklishinmergify[bot]
authored andcommitted
Make sure protected_from_deletion is included into virtual host definitions exported over the HTTP API
(cherry picked from commit 315c247)
1 parent 5550c91 commit 687d5f9

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,17 @@ add_vhost(VHost, ActingUser) ->
786786
case rabbit_vhost:put_vhost(Name, Description, Tags, DefaultQueueType, IsTracingEnabled, ActingUser) of
787787
ok ->
788788
ok;
789-
{error, _} = Err ->
790-
throw(Err)
789+
{error, _} = Err1 ->
790+
throw(Err1)
791+
end,
792+
793+
%% The newly created virtual host won't have all the metadata keys. Rather than
794+
%% changing the functions above, simply update the metadata as a separate step.
795+
case rabbit_vhost:update_metadata(Name, Metadata, ActingUser) of
796+
ok ->
797+
ok;
798+
{error, _} = Err2 ->
799+
throw(Err2)
791800
end.
792801

793802
add_permission(Permission, ActingUser) ->

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ declare_default_exchanges(VHostName, ActingUser) ->
253253
end, DefaultExchanges).
254254

255255
-spec update_metadata(vhost:name(), vhost:metadata(), rabbit_types:username()) -> rabbit_types:ok_or_error(any()).
256+
update_metadata(Name, undefined, _ActingUser) ->
257+
case rabbit_db_vhost:exists(Name) of
258+
true ->
259+
ok;
260+
false ->
261+
{error, {no_such_vhost, Name}}
262+
end;
263+
update_metadata(Name, Metadata0, _ActingUser) when is_map(Metadata0) andalso map_size(Metadata0) =:= 0 ->
264+
case rabbit_db_vhost:exists(Name) of
265+
true ->
266+
ok;
267+
false ->
268+
{error, {no_such_vhost, Name}}
269+
end;
256270
update_metadata(Name, Metadata0, ActingUser) ->
257271
KnownKeys = [description, tags, default_queue_type, protected_from_deletion],
258272
Metadata = maps:with(KnownKeys, Metadata0),

deps/rabbit/test/definition_import_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ import_case16(Config) ->
273273
Val when is_tuple(Val) ->
274274
?assertEqual(<<"A case16 description">>, vhost:get_description(VHostRec)),
275275
?assertEqual(<<"quorum">>, vhost:get_default_queue_type(VHostRec)),
276-
?assertEqual([multi_dc_replication,ab,cde], vhost:get_tags(VHostRec))
276+
?assertEqual([<<"multi_dc_replication">>,<<"ab">>,<<"cde">>], vhost:get_tags(VHostRec))
277277
end,
278278

279279
ok.

deps/rabbitmq_management/src/rabbit_mgmt_wm_vhosts.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ augmented(ReqData, #context{user = User}) ->
6969
basic() ->
7070
Maps = lists:map(
7171
fun maps:from_list/1,
72-
rabbit_vhost:info_all([name, description, tags, default_queue_type, metadata])),
72+
rabbit_vhost:info_all([name, description, tags, default_queue_type, metadata, protected_from_deletion])),
7373
rabbit_queue_type:vhosts_with_dqt(Maps).

0 commit comments

Comments
 (0)