Skip to content

Commit 1cf5477

Browse files
lukebakkenmichaelklishin
authored andcommitted
Add vhost:new_metadata function
1 parent d6fa3b7 commit 1cf5477

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ update_metadata(Name, Metadata0, ActingUser) ->
250250

251251
-spec update(vhost:name(), binary(), [atom()], rabbit_queue_type:queue_type() | 'undefined', rabbit_types:username()) -> rabbit_types:ok_or_error(any()).
252252
update(Name, Description, Tags, DefaultQueueType, ActingUser) ->
253-
Metadata = #{description => Description, tags => Tags, default_queue_type => DefaultQueueType},
253+
Metadata = vhost:new_metadata(Description, Tags, DefaultQueueType),
254254
update_metadata(Name, Metadata, ActingUser).
255255

256256
-spec delete(vhost:name(), rabbit_types:username()) -> rabbit_types:ok_or_error(any()).
257-
258257
delete(VHost, ActingUser) ->
259258
%% FIXME: We are forced to delete the queues and exchanges outside
260259
%% the TX below. Queue deletion involves sending messages to the queue
@@ -298,7 +297,7 @@ delete(VHost, ActingUser) ->
298297
-spec put_vhost(vhost:name(),
299298
binary(),
300299
vhost:unparsed_tags() | vhost:tags(),
301-
rabbit_queue_type:queue_type() | 'undefined',
300+
rabbit_queue_type:queue_type() | 'undefined' | binary(),
302301
boolean(),
303302
rabbit_types:username()) ->
304303
'ok' | {'error', any()} | {'EXIT', any()}.
@@ -310,25 +309,14 @@ put_vhost(Name, Description, Tags0, DefaultQueueType0, Trace, Username) ->
310309
"null" -> <<"">>;
311310
Other -> Other
312311
end,
313-
DefaultQueueType = case DefaultQueueType0 of
314-
<<"undefined">> -> undefined;
315-
_ -> DefaultQueueType0
316-
end,
312+
DefaultQueueType = rabbit_data_coercion:to_atom(DefaultQueueType0),
317313
ParsedTags = parse_tags(Tags),
318314
rabbit_log:debug("Parsed tags ~tp to ~tp", [Tags, ParsedTags]),
319315
Result = case exists(Name) of
320316
true ->
321317
update(Name, Description, ParsedTags, DefaultQueueType, Username);
322318
false ->
323-
Metadata0 = #{description => Description,
324-
tags => ParsedTags},
325-
Metadata = case DefaultQueueType of
326-
undefined ->
327-
Metadata0;
328-
_ ->
329-
Metadata0#{default_queue_type =>
330-
DefaultQueueType}
331-
end,
319+
Metadata = vhost:new_metadata(Description, ParsedTags, DefaultQueueType),
332320
case catch do_add(Name, Metadata, Username) of
333321
ok ->
334322
%% wait for up to 45 seconds for the vhost to initialise

deps/rabbit/src/vhost.erl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
set_limits/2,
3030
set_metadata/2,
3131
merge_metadata/2,
32+
new_metadata/3,
3233
is_tagged_with/2
3334
]).
3435

@@ -183,6 +184,15 @@ metadata_merger(default_queue_type, _, NewVHostDefaultQueueType) ->
183184
metadata_merger(_, _, NewMetadataValue) ->
184185
NewMetadataValue.
185186

187+
-spec new_metadata(binary(), [atom()], rabbit_queue_type:queue_type() | 'undefined') -> metadata().
188+
new_metadata(Description, Tags, undefined) ->
189+
#{description => Description,
190+
tags => Tags};
191+
new_metadata(Description, Tags, DefaultQueueType) ->
192+
#{description => Description,
193+
tags => Tags,
194+
default_queue_type => DefaultQueueType}.
195+
186196
-spec is_tagged_with(vhost(), tag()) -> boolean().
187197
is_tagged_with(VHost, Tag) ->
188198
lists:member(Tag, get_tags(VHost)).

0 commit comments

Comments
 (0)