Skip to content

Commit

Permalink
fix: Use cowboy callbacks io vhost_or_not_found
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisSotoLopez committed Apr 4, 2024
1 parent cf497a9 commit f278600
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 1 addition & 7 deletions deps/rabbitmq_management/src/rabbit_mgmt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% TODO sort all this out; maybe there's scope for rabbit_mgmt_request?

-export([is_authorized/2, is_authorized_admin/2, is_authorized_admin/4,
is_authorized_admin/3, vhost/1, vhost_or_not_found/2, vhost_from_headers/1]).
is_authorized_admin/3, vhost/1, vhost_from_headers/1]).
-export([is_authorized_vhost/2, is_authorized_user/3,
is_authorized_user/4, is_authorized_user/5,
is_authorized_monitor/2, is_authorized_policies/2,
Expand Down Expand Up @@ -210,12 +210,6 @@ vhost_from_headers(ReqData) ->
vhost(ReqData) ->
rabbit_web_dispatch_access_control:vhost(ReqData).

vhost_or_not_found(ReqData, Context) ->
case rabbit_web_dispatch_access_control:vhost(ReqData) of
not_found -> not_found(<<"virtual host not found">>, ReqData, Context);
VHost -> VHost
end.

user(ReqData) ->
case id(user, ReqData) of
none -> not_found;
Expand Down
7 changes: 5 additions & 2 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_get.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

-export([init/2, resource_exists/2, is_authorized/2,
allowed_methods/2, accept_content/2, content_types_provided/2,
content_types_accepted/2]).
content_types_accepted/2, allow_missing_post/2]).
-export([variances/2]).

-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
Expand All @@ -35,14 +35,17 @@ resource_exists(ReqData, Context) ->
_ -> true
end, ReqData, Context}.

allow_missing_post(Req, Context) ->
{false, Req, Context}.

content_types_accepted(ReqData, Context) ->
{[{'*', accept_content}], ReqData, Context}.

accept_content(ReqData, Context) ->
rabbit_mgmt_util:post_respond(do_it(ReqData, Context)).

do_it(ReqData0, Context) ->
VHost = rabbit_mgmt_util:vhost_or_not_found(ReqData0, Context),
VHost = rabbit_mgmt_util:vhost(ReqData0),
Q = rabbit_mgmt_util:id(queue, ReqData0),
rabbit_mgmt_util:with_decode(
[ackmode, count, encoding], ReqData0, Context,
Expand Down

0 comments on commit f278600

Please sign in to comment.