Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Switch operator policies and vhost limit endpoints to use dashes
Browse files Browse the repository at this point in the history
Like we already do with aliveness-check and a few other things.
These endpoints are new in 3.7.0/master and we should unify them while
we can.

Per suggestion from @acogoluegnes.

References rabbitmq/rabbitmq-server#500, rabbitmq/rabbitmq-server#501,
rabbitmq/rabbitmq-server#930.
  • Loading branch information
michaelklishin committed Jan 3, 2017
1 parent 8792baf commit e9e2e5d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
12 changes: 9 additions & 3 deletions bin/rabbitmqadmin
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ URIS = {
'permission': '/permissions/{vhost}/{user}',
'parameter': '/parameters/{component}/{vhost}/{name}',
'policy': '/policies/{vhost}/{name}',
'operator_policy': '/operator_policies/{vhost}/{name}',
'vhost_limit': '/vhost_limits/{vhost}/{name}'
'operator_policy': '/operator-policies/{vhost}/{name}',
'vhost_limit': '/vhost-limits/{vhost}/{name}'
}

DECLARABLE = {
Expand Down Expand Up @@ -603,12 +603,18 @@ class Management:
(uri, obj_info, cols) = self.list_show_uri(SHOWABLE, 'show')
format_list('[{0}]'.format(self.get(uri)), cols, obj_info, self.options)

def _list_path_for_obj_type(self, obj_type):
# This returns a URL path for given object type, e.g.
# replaces underscores in command names with
# dashes that HTTP API endpoints use
return obj_type.replace("_", "-")

def list_show_uri(self, obj_types, verb):
obj_type = self.args[0]
assert_usage(obj_type in obj_types,
"Don't know how to {0} {1}".format(verb, obj_type))
obj_info = obj_types[obj_type]
uri = "/%s" % obj_type
uri = "/%s" % self._list_path_for_obj_type(obj_type)
query = []
if obj_info['vhost'] and self.options.vhost:
uri += "/%s" % quote_plus(self.options.vhost)
Expand Down
14 changes: 7 additions & 7 deletions src/rabbit_mgmt_dispatcher.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ dispatcher() ->
{"/policies", rabbit_mgmt_wm_policies, []},
{"/policies/:vhost", rabbit_mgmt_wm_policies, []},
{"/policies/:vhost/:name", rabbit_mgmt_wm_policy, []},
{"/operator_policies", rabbit_mgmt_wm_operator_policies, []},
{"/operator_policies/:vhost", rabbit_mgmt_wm_operator_policies, []},
{"/operator_policies", rabbit_mgmt_wm_operator_policies, []},
{"/operator_policies/:vhost/:name", rabbit_mgmt_wm_operator_policy, []},
{"/vhost_limits/:vhost/:name", rabbit_mgmt_wm_limit, []},
{"/vhost_limits", rabbit_mgmt_wm_limits, []},
{"/vhost_limits/:vhost", rabbit_mgmt_wm_limits, []},
{"/operator-policies", rabbit_mgmt_wm_operator_policies, []},
{"/operator-policies/:vhost", rabbit_mgmt_wm_operator_policies, []},
{"/operator-policies", rabbit_mgmt_wm_operator_policies, []},
{"/operator-policies/:vhost/:name", rabbit_mgmt_wm_operator_policy, []},
{"/vhost-limits/:vhost/:name", rabbit_mgmt_wm_limit, []},
{"/vhost-limits", rabbit_mgmt_wm_limits, []},
{"/vhost-limits/:vhost", rabbit_mgmt_wm_limits, []},
{"/connections", rabbit_mgmt_wm_connections, []},
{"/connections/:connection", rabbit_mgmt_wm_connection, []},
{"/connections/:connection/channels", rabbit_mgmt_wm_connection_channels, []},
Expand Down
64 changes: 32 additions & 32 deletions test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2104,17 +2104,17 @@ cors_test(Config) ->
passed.

vhost_limits_list_test(Config) ->
[] = http_get(Config, "/vhost_limits", ?OK),
[] = http_get(Config, "/vhost-limits", ?OK),

http_get(Config, "/vhost_limits/limit_test_vhost_1", ?NOT_FOUND),
http_get(Config, "/vhost-limits/limit_test_vhost_1", ?NOT_FOUND),
rabbit_ct_broker_helpers:add_vhost(Config, <<"limit_test_vhost_1">>),

[] = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
http_get(Config, "/vhost_limits/limit_test_vhost_2", ?NOT_FOUND),
[] = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),
http_get(Config, "/vhost-limits/limit_test_vhost_2", ?NOT_FOUND),

rabbit_ct_broker_helpers:add_vhost(Config, <<"limit_test_vhost_2">>),

[] = http_get(Config, "/vhost_limits/limit_test_vhost_2", ?OK),
[] = http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK),

Limits1 = #{'max-connections' => 100, 'max-queues' => 100},
Limits2 = #{'max-connections' => 200},
Expand All @@ -2130,59 +2130,59 @@ vhost_limits_list_test(Config) ->
ok = rabbit_ct_broker_helpers:set_parameter(Config, 0, VHost, <<"vhost-limits">>, <<"limits">>, Param)
end,
Expected),
Expected = http_get(Config, "/vhost_limits", ?OK),
Limits1 = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
Limits2 = http_get(Config, "/vhost_limits/limit_test_vhost_2", ?OK),
Expected = http_get(Config, "/vhost-limits", ?OK),
Limits1 = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),
Limits2 = http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK),

NoVhostUser = <<"no_vhost_user">>,
rabbit_ct_broker_helpers:add_user(Config, NoVhostUser),
rabbit_ct_broker_helpers:set_user_tags(Config, 0, NoVhostUser, [management]),
[] = http_get(Config, "/vhost_limits", NoVhostUser, NoVhostUser, ?OK),
http_get(Config, "/vhost_limits/limit_test_vhost_1", NoVhostUser, NoVhostUser, ?NOT_AUTHORISED),
http_get(Config, "/vhost_limits/limit_test_vhost_2", NoVhostUser, NoVhostUser, ?NOT_AUTHORISED),
[] = http_get(Config, "/vhost-limits", NoVhostUser, NoVhostUser, ?OK),
http_get(Config, "/vhost-limits/limit_test_vhost_1", NoVhostUser, NoVhostUser, ?NOT_AUTHORISED),
http_get(Config, "/vhost-limits/limit_test_vhost_2", NoVhostUser, NoVhostUser, ?NOT_AUTHORISED),

Vhost1User = <<"limit_test_vhost_1_user">>,
rabbit_ct_broker_helpers:add_user(Config, Vhost1User),
rabbit_ct_broker_helpers:set_user_tags(Config, 0, Vhost1User, [management]),
rabbit_ct_broker_helpers:set_full_permissions(Config, Vhost1User, <<"limit_test_vhost_1">>),
[#{vhost := <<"limit_test_vhost_1">>, value := Limits1}] =
http_get(Config, "/vhost_limits", Vhost1User, Vhost1User, ?OK),
Limits1 = http_get(Config, "/vhost_limits/limit_test_vhost_1", Vhost1User, Vhost1User, ?OK),
http_get(Config, "/vhost_limits/limit_test_vhost_2", Vhost1User, Vhost1User, ?NOT_AUTHORISED),
http_get(Config, "/vhost-limits", Vhost1User, Vhost1User, ?OK),
Limits1 = http_get(Config, "/vhost-limits/limit_test_vhost_1", Vhost1User, Vhost1User, ?OK),
http_get(Config, "/vhost-limits/limit_test_vhost_2", Vhost1User, Vhost1User, ?NOT_AUTHORISED),

Vhost2User = <<"limit_test_vhost_2_user">>,
rabbit_ct_broker_helpers:add_user(Config, Vhost2User),
rabbit_ct_broker_helpers:set_user_tags(Config, 0, Vhost2User, [management]),
rabbit_ct_broker_helpers:set_full_permissions(Config, Vhost2User, <<"limit_test_vhost_2">>),
[#{vhost := <<"limit_test_vhost_2">>, value := Limits2}] =
http_get(Config, "/vhost_limits", Vhost2User, Vhost2User, ?OK),
http_get(Config, "/vhost_limits/limit_test_vhost_1", Vhost2User, Vhost2User, ?NOT_AUTHORISED),
Limits2 = http_get(Config, "/vhost_limits/limit_test_vhost_2", Vhost2User, Vhost2User, ?OK).
http_get(Config, "/vhost-limits", Vhost2User, Vhost2User, ?OK),
http_get(Config, "/vhost-limits/limit_test_vhost_1", Vhost2User, Vhost2User, ?NOT_AUTHORISED),
Limits2 = http_get(Config, "/vhost-limits/limit_test_vhost_2", Vhost2User, Vhost2User, ?OK).

vhost_limit_set_test(Config) ->
[] = http_get(Config, "/vhost_limits", ?OK),
[] = http_get(Config, "/vhost-limits", ?OK),
rabbit_ct_broker_helpers:add_vhost(Config, <<"limit_test_vhost_1">>),
[] = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
[] = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),

%% Set a limit
http_put(Config, "/vhost_limits/limit_test_vhost_1/max-queues", [{value, 100}], ?NO_CONTENT),
http_put(Config, "/vhost-limits/limit_test_vhost_1/max-queues", [{value, 100}], ?NO_CONTENT),

#{'max-queues' := 100} = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
#{'max-queues' := 100} = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),

%% Set another limit
http_put(Config, "/vhost_limits/limit_test_vhost_1/max-connections", [{value, 200}], ?NO_CONTENT),
http_put(Config, "/vhost-limits/limit_test_vhost_1/max-connections", [{value, 200}], ?NO_CONTENT),

#{'max-connections' := 200,
'max-queues' := 100} = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
'max-queues' := 100} = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),

[#{vhost := <<"limit_test_vhost_1">>,
value := #{'max-connections' := 200,
'max-queues' := 100}}] = http_get(Config, "/vhost_limits", ?OK),
'max-queues' := 100}}] = http_get(Config, "/vhost-limits", ?OK),

%% Update a limit
http_put(Config, "/vhost_limits/limit_test_vhost_1/max-connections", [{value, 1000}], ?NO_CONTENT),
http_put(Config, "/vhost-limits/limit_test_vhost_1/max-connections", [{value, 1000}], ?NO_CONTENT),
#{'max-connections' := 1000,
'max-queues' := 100} = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
'max-queues' := 100} = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),


Vhost1User = <<"limit_test_vhost_1_user">>,
Expand All @@ -2191,20 +2191,20 @@ vhost_limit_set_test(Config) ->
rabbit_ct_broker_helpers:set_full_permissions(Config, Vhost1User, <<"limit_test_vhost_1">>),

#{'max-connections' := 1000,
'max-queues' := 100} = http_get(Config, "/vhost_limits/limit_test_vhost_1", Vhost1User, Vhost1User, ?OK),
'max-queues' := 100} = http_get(Config, "/vhost-limits/limit_test_vhost_1", Vhost1User, Vhost1User, ?OK),

%% Only admin can update limits
http_put(Config, "/vhost_limits/limit_test_vhost_1/max-connections", [{value, 300}], ?NO_CONTENT),
http_put(Config, "/vhost-limits/limit_test_vhost_1/max-connections", [{value, 300}], ?NO_CONTENT),

%% Clear a limit
http_delete(Config, "/vhost_limits/limit_test_vhost_1/max-connections", ?NO_CONTENT),
#{'max-queues' := 100} = http_get(Config, "/vhost_limits/limit_test_vhost_1", ?OK),
http_delete(Config, "/vhost-limits/limit_test_vhost_1/max-connections", ?NO_CONTENT),
#{'max-queues' := 100} = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),

%% Only admin can clear limits
http_delete(Config, "/vhost_limits/limit_test_vhost_1/max-queues", Vhost1User, Vhost1User, ?NOT_AUTHORISED),
http_delete(Config, "/vhost-limits/limit_test_vhost_1/max-queues", Vhost1User, Vhost1User, ?NOT_AUTHORISED),

%% Unknown limit error
http_put(Config, "/vhost_limits/limit_test_vhost_1/max-channels", [{value, 200}], ?BAD_REQUEST).
http_put(Config, "/vhost-limits/limit_test_vhost_1/max-channels", [{value, 200}], ?BAD_REQUEST).

rates_test(Config) ->
http_put(Config, "/queues/%2f/myqueue", none, {group, '2xx'}),
Expand Down

0 comments on commit e9e2e5d

Please sign in to comment.