Skip to content

Commit d478fad

Browse files
Type specs around virtual host addition
1 parent f1a922a commit d478fad

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

deps/rabbit/src/rabbit_queue_type.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
-type arguments() :: queue_arguments | consumer_arguments.
5656
-type queue_type() :: rabbit_classic_queue | rabbit_quorum_queue | rabbit_stream_queue.
5757

58+
-export_type([queue_type/0]).
59+
5860
-define(STATE, ?MODULE).
5961

6062
%% Recoverable mirrors shouldn't really be a generic one, but let's keep it here until

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,22 @@ delete(VHost, ActingUser) ->
286286
rabbit_vhost_sup_sup:delete_on_all_nodes(VHost),
287287
ok.
288288

289+
-spec put_vhost(vhost:name(),
290+
binary(),
291+
vhost:tags(),
292+
boolean(),
293+
rabbit_types:username()) ->
294+
'ok' | {'error', any()} | {'EXIT', any()}.
289295
put_vhost(Name, Description, Tags0, Trace, Username) ->
290296
put_vhost(Name, Description, Tags0, undefined, Trace, Username).
291297

298+
-spec put_vhost(vhost:name(),
299+
binary(),
300+
vhost:unparsed_tags() | vhost:tags(),
301+
rabbit_queue_type:queue_type(),
302+
boolean(),
303+
rabbit_types:username()) ->
304+
'ok' | {'error', any()} | {'EXIT', any()}.
292305
put_vhost(Name, Description, Tags0, DefaultQueueType, Trace, Username) ->
293306
Tags = case Tags0 of
294307
undefined -> <<"">>;
@@ -333,10 +346,13 @@ put_vhost(Name, Description, Tags0, DefaultQueueType, Trace, Username) ->
333346
end,
334347
Result.
335348

349+
-spec is_over_vhost_limit(vhost:name()) -> 'ok' | no_return().
336350
is_over_vhost_limit(Name) ->
337351
Limit = rabbit_misc:get_env(rabbit, vhost_max, infinity),
338352
is_over_vhost_limit(Name, Limit).
339353

354+
-spec is_over_vhost_limit(vhost:name(), 'infinity' | non_neg_integer())
355+
-> 'ok' | no_return().
340356
is_over_vhost_limit(_Name, infinity) ->
341357
ok;
342358
is_over_vhost_limit(Name, Limit) when is_integer(Limit) ->

deps/rabbit/src/vhost.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
-type(description() :: binary()).
4848
-type(tag() :: atom()).
49+
-type(tags() :: [tag()]).
50+
-type(unparsed_tags() :: binary() | string() | atom()).
4951

5052
-type vhost() :: vhost_v2().
5153

@@ -76,6 +78,8 @@
7678
metadata/0,
7779
description/0,
7880
tag/0,
81+
unparsed_tags/0,
82+
tags/0,
7983
vhost/0,
8084
vhost_v2/0,
8185
vhost_pattern/0,

deps/rabbitmq_management/src/rabbit_mgmt_wm_vhost.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
-export([init/2, resource_exists/2, to_json/2,
1111
content_types_provided/2, content_types_accepted/2,
1212
is_authorized/2, allowed_methods/2, accept_content/2,
13-
delete_resource/2, id/1, put_vhost/6]).
13+
delete_resource/2, id/1]).
1414
-export([variances/2]).
1515

1616
-import(rabbit_misc, [pget/2]).
1717

1818
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
1919
-include_lib("rabbit_common/include/rabbit.hrl").
2020

21+
-dialyzer({nowarn_function, accept_content/2}).
22+
2123
%%--------------------------------------------------------------------
2224

2325
init(Req, _State) ->
@@ -67,20 +69,20 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
6769
%% so fall back to it. See rabbitmq/rabbitmq-server#7734.
6870
FallbackQT = maps:get(defaultqueuetype, BodyMap, undefined),
6971
DefaultQT = maps:get(default_queue_type, BodyMap, FallbackQT),
70-
case put_vhost(Name, Description, Tags, DefaultQT, Trace, Username) of
72+
case rabbit_vhost:put_vhost(Name, Description, Tags, DefaultQT, Trace, Username) of
7173
ok ->
7274
{true, ReqData, Context};
73-
{'EXIT', {vhost_limit_exceeded,
74-
Explanation}} ->
75-
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context);
7675
{error, timeout} = E ->
7776
rabbit_mgmt_util:internal_server_error(
7877
"Timed out while waiting for the vhost to initialise", E,
7978
ReqData0, Context);
8079
{error, E} ->
8180
rabbit_mgmt_util:internal_server_error(
8281
"Error occured while adding vhost", E,
83-
ReqData0, Context)
82+
ReqData0, Context);
83+
{'EXIT', {vhost_limit_exceeded,
84+
Explanation}} ->
85+
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context)
8486
end
8587
end).
8688

@@ -104,5 +106,3 @@ id(ReqData) ->
104106
Value -> Value
105107
end.
106108

107-
put_vhost(Name, Description, Tags, DefaultQT, Trace, Username) ->
108-
rabbit_vhost:put_vhost(Name, Description, Tags, DefaultQT, Trace, Username).

0 commit comments

Comments
 (0)