Skip to content

Commit e610ada

Browse files
Merge pull request #10908 from cloudamqp/fix/10901-unhandled-function-clause-on-nonexistent-virtual-host
Handle non-existent virtual host in several HTTP API endpoints
2 parents ca69084 + 383ddb1 commit e610ada

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_exchange_publish.erl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
-module(rabbit_mgmt_wm_exchange_publish).
99

10-
-export([init/2, resource_exists/2, is_authorized/2,
10+
-export([init/2, resource_exists/2, allow_missing_post/2, is_authorized/2,
1111
allowed_methods/2, content_types_provided/2, accept_content/2,
1212
content_types_accepted/2]).
1313
-export([variances/2]).
@@ -31,10 +31,13 @@ content_types_provided(ReqData, Context) ->
3131

3232
resource_exists(ReqData, Context) ->
3333
{case rabbit_mgmt_wm_exchange:exchange(ReqData) of
34-
not_found -> false;
34+
not_found -> raise_not_found(ReqData, Context);
3535
_ -> true
3636
end, ReqData, Context}.
3737

38+
allow_missing_post(ReqData, Context) ->
39+
{false, ReqData, Context}.
40+
3841
content_types_accepted(ReqData, Context) ->
3942
{[{'*', accept_content}], ReqData, Context}.
4043

@@ -101,6 +104,18 @@ bad({{coordinator_unavailable, _}, _}, ReqData, Context) ->
101104
is_authorized(ReqData, Context) ->
102105
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
103106

107+
raise_not_found(ReqData, Context) ->
108+
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
109+
not_found ->
110+
"vhost_not_found";
111+
_ ->
112+
"exchange_not_found"
113+
end,
114+
rabbit_mgmt_util:not_found(
115+
rabbit_data_coercion:to_binary(ErrorMessage),
116+
ReqData,
117+
Context).
118+
104119
%%--------------------------------------------------------------------
105120

106121
decode(Payload, <<"string">>) -> Payload;

deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_actions.erl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
-module(rabbit_mgmt_wm_queue_actions).
99

10-
-export([init/2, resource_exists/2, is_authorized/2,
10+
-export([init/2, resource_exists/2, is_authorized/2, allow_missing_post/2,
1111
allowed_methods/2, content_types_accepted/2, accept_content/2]).
1212
-export([variances/2]).
1313

@@ -28,10 +28,13 @@ allowed_methods(ReqData, Context) ->
2828

2929
resource_exists(ReqData, Context) ->
3030
{case rabbit_mgmt_wm_queue:queue(ReqData) of
31-
not_found -> false;
31+
not_found -> raise_not_found(ReqData, Context);
3232
_ -> true
3333
end, ReqData, Context}.
3434

35+
allow_missing_post(ReqData, Context) ->
36+
{false, ReqData, Context}.
37+
3538
content_types_accepted(ReqData, Context) ->
3639
{[{'*', accept_content}], ReqData, Context}.
3740

@@ -52,6 +55,17 @@ do_it(ReqData0, Context) ->
5255
is_authorized(ReqData, Context) ->
5356
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).
5457

58+
raise_not_found(ReqData, Context) ->
59+
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
60+
not_found ->
61+
"vhost_not_found";
62+
_ ->
63+
"queue_not_found"
64+
end,
65+
rabbit_mgmt_util:not_found(
66+
rabbit_data_coercion:to_binary(ErrorMessage),
67+
ReqData,
68+
Context).
5569
%%--------------------------------------------------------------------
5670

5771
action(<<"sync">>, Q, ReqData, Context) when ?is_amqqueue(Q) ->

deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_get.erl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
-module(rabbit_mgmt_wm_queue_get).
99

10-
-export([init/2, resource_exists/2, is_authorized/2,
10+
-export([init/2, resource_exists/2, is_authorized/2, allow_missing_post/2,
1111
allowed_methods/2, accept_content/2, content_types_provided/2,
1212
content_types_accepted/2]).
1313
-export([variances/2]).
@@ -31,10 +31,13 @@ content_types_provided(ReqData, Context) ->
3131

3232
resource_exists(ReqData, Context) ->
3333
{case rabbit_mgmt_wm_queue:queue(ReqData) of
34-
not_found -> false;
34+
not_found -> raise_not_found(ReqData, Context);
3535
_ -> true
3636
end, ReqData, Context}.
3737

38+
allow_missing_post(ReqData, Context) ->
39+
{false, ReqData, Context}.
40+
3841
content_types_accepted(ReqData, Context) ->
3942
{[{'*', accept_content}], ReqData, Context}.
4043

@@ -149,6 +152,17 @@ basic_get(Ch, Q, AckMode, Enc, Trunc) ->
149152
is_authorized(ReqData, Context) ->
150153
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
151154

155+
raise_not_found(ReqData, Context) ->
156+
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
157+
not_found ->
158+
"vhost_not_found";
159+
_ ->
160+
"queue_not_found"
161+
end,
162+
rabbit_mgmt_util:not_found(
163+
rabbit_data_coercion:to_binary(ErrorMessage),
164+
ReqData,
165+
Context).
152166
%%--------------------------------------------------------------------
153167

154168
maybe_truncate(Payload, none) -> Payload;

0 commit comments

Comments
 (0)