Use different not_found msg for vhosts & resources

Issue #10901

(cherry picked from commit 383ddb1634)
This commit is contained in:
Lois Soto Lopez 2024-04-10 10:03:25 +02:00 committed by Mergify
parent 02592bf125
commit a4465d7a72
3 changed files with 40 additions and 15 deletions

View File

@ -31,15 +31,12 @@ content_types_provided(ReqData, Context) ->
resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_exchange:exchange(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.
allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.
content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
@ -107,6 +104,18 @@ bad({{coordinator_unavailable, _}, _}, ReqData, Context) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"exchange_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).
%%--------------------------------------------------------------------
decode(Payload, <<"string">>) -> Payload;

View File

@ -28,15 +28,12 @@ allowed_methods(ReqData, Context) ->
resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_queue:queue(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.
allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.
content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
@ -58,6 +55,17 @@ do_it(ReqData0, Context) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).
raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"queue_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).
%%--------------------------------------------------------------------
action(<<"sync">>, Q, ReqData, Context) when ?is_amqqueue(Q) ->

View File

@ -31,15 +31,12 @@ content_types_provided(ReqData, Context) ->
resource_exists(ReqData, Context) ->
{case rabbit_mgmt_wm_queue:queue(ReqData) of
not_found -> false;
not_found -> raise_not_found(ReqData, Context);
_ -> true
end, ReqData, Context}.
allow_missing_post(ReqData, Context) ->
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData,
Context).
{false, ReqData, Context}.
content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.
@ -155,6 +152,17 @@ basic_get(Ch, Q, AckMode, Enc, Trunc) ->
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
raise_not_found(ReqData, Context) ->
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
not_found ->
"vhost_not_found";
_ ->
"queue_not_found"
end,
rabbit_mgmt_util:not_found(
rabbit_data_coercion:to_binary(ErrorMessage),
ReqData,
Context).
%%--------------------------------------------------------------------
maybe_truncate(Payload, none) -> Payload;