Display operator policies for queues

This commit is contained in:
Daniil Fedotov 2016-08-25 17:09:06 +01:00
parent b992a87567
commit a2f626864d
8 changed files with 140 additions and 5 deletions

View File

@ -209,6 +209,7 @@ dispatcher_add(function(sammy) {
return false;
});
path('#/policies', {'policies': '/policies',
'operator_policies': '/operator_policies',
'vhosts': '/vhosts'}, 'policies');
sammy.get('#/policies/:vhost/:id', function() {
render({'policy': '/policies/' + esc(this.params['vhost'])

View File

@ -78,10 +78,22 @@ function fmt_features(obj) {
}
function fmt_policy_short(obj) {
if (obj.policy != undefined && obj.policy != '') {
var policy = obj.policy;
if (policy != undefined && policy != '') {
return '<acronym class="policy" title="Policy: ' +
fmt_escape_html(obj.policy) + '">' +
fmt_escape_html(obj.policy) + '</acronym> ';
fmt_escape_html(policy) + '">' +
fmt_escape_html(policy) + '</acronym> ';
} else {
return '';
}
}
function fmt_op_policy_short(obj) {
var op_policy = obj.operator_policy;
if (op_policy != undefined && op_policy != '') {
return '<acronym class="policy" title="Operator policy: ' +
fmt_escape_html(op_policy) + '">' +
fmt_escape_html(op_policy) + '</acronym> ';
} else {
return '';
}

View File

@ -1,6 +1,6 @@
<h1>Policies</h1>
<div class="section">
<h2>All policies</h2>
<h2>User policies</h2>
<div class="hider">
<%= filter_ui(policies) %>
<div class="updatable">
@ -46,6 +46,51 @@
</div>
</div>
</div>
<div class="section">
<h2>Operator policies</h2>
<div class="hider">
<%= filter_ui(operator_policies) %>
<div class="updatable">
<% if (operator_policies.length > 0) { %>
<table class="list">
<thead>
<tr>
<% if (vhosts_interesting) { %>
<th>Virtual Host</th>
<% } %>
<th>Name</th>
<th>Pattern</th>
<th>Apply to</th>
<th>Definition</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
<%
for (var i = 0; i < operator_policies.length; i++) {
var policy = operator_policies[i];
%>
<tr<%= alt_rows(i)%>>
<% if (vhosts_interesting) { %>
<td><%= fmt_string(policy.vhost) %></td>
<% } %>
<td><%= fmt_string(policy.name) %></td>
<td><%= fmt_string(policy.pattern) %></td>
<td><%= fmt_string(policy['apply-to']) %></td>
<td><%= fmt_table_short(policy.definition) %></td>
<td><%= fmt_string(policy.priority) %></td>
</tr>
<% } %>
</tbody>
</table>
<% } else { %>
<p>... no policies ...</p>
<% } %>
</div>
</div>
</div>
<% if (is_user_policymaker) { %>
<div class="section-hidden">

View File

@ -18,6 +18,14 @@
<th>Policy</th>
<td><%= fmt_string(queue.policy, '') %></td>
</tr>
<tr>
<th>Operator policy</th>
<td><%= fmt_string(queue.operator_policy, '') %></td>
</tr>
<tr>
<th>Effective policy definition</th>
<td><%= fmt_table_short(queue.effective_policy_definition) %></td>
</tr>
<% if (queue.owner_pid_details != undefined) { %>
<tr>
<th>Exclusive owner</th>

View File

@ -110,13 +110,15 @@
<td class="c">
<%= fmt_features_short(queue) %>
<%= fmt_policy_short(queue) %>
<%= fmt_op_policy_short(queue) %>
</td>
<% } %>
<% if (show_column('queues', 'features_no_policy')) { %>
<td class="c"><%= fmt_features_short(queue) %></td>
<% } %>
<% if (show_column('queues', 'policy')) { %>
<td class="c"><%= fmt_string(queue.policy) %></td>
<td class="c"><%= fmt_string(queue.policy) %>
<%= fmt_string(queue.operator_policy) %></td>
<% } %>
<% if (show_column('queues', 'consumers')) { %>
<td class="c"><%= fmt_string(queue.consumers) %></td>

View File

@ -71,6 +71,8 @@ dispatcher() ->
{"/parameters/:component", rabbit_mgmt_wm_parameters, []},
{"/parameters/:component/:vhost", rabbit_mgmt_wm_parameters, []},
{"/parameters/:component/:vhost/:name", rabbit_mgmt_wm_parameter, []},
{"/operator_policies", rabbit_mgmt_wm_operator_policies, []},
{"/operator_policies/:vhost", rabbit_mgmt_wm_operator_policies, []},
{"/policies", rabbit_mgmt_wm_policies, []},
{"/policies/:vhost", rabbit_mgmt_wm_policies, []},
{"/policies/:vhost/:name", rabbit_mgmt_wm_policy, []},

View File

@ -101,6 +101,8 @@ format_connection_created(Stat) ->
format_exchange_and_queue({policy, Value}) ->
policy(Value);
format_exchange_and_queue({operator_policy, Value}) ->
operator_policy(Value);
format_exchange_and_queue({arguments, Value}) ->
[{arguments, amqp_table(Value)}];
format_exchange_and_queue({name, Value}) ->
@ -227,6 +229,9 @@ resource(NameAs, #resource{name = Name, virtual_host = VHost}) ->
policy('') -> [];
policy(Policy) -> [{policy, Policy}].
operator_policy('') -> [];
operator_policy(Policy) -> [{operator_policy, Policy}].
internal_user(User) ->
[{name, User#internal_user.username},
{password_hash, base64:encode(User#internal_user.password_hash)},

View File

@ -0,0 +1,60 @@
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License at
%% http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
%% License for the specific language governing rights and limitations
%% under the License.
%%
%% The Original Code is RabbitMQ Management Plugin.
%%
%% The Initial Developer of the Original Code is GoPivotal, Inc.
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
%%
-module(rabbit_mgmt_wm_operator_policies).
-export([init/3, rest_init/2, to_json/2, content_types_provided/2, is_authorized/2,
resource_exists/2, basic/1]).
-export([variances/2]).
-include("rabbit_mgmt.hrl").
-include_lib("rabbit_common/include/rabbit.hrl").
%%--------------------------------------------------------------------
init(_, _, _) -> {upgrade, protocol, cowboy_rest}.
rest_init(Req, _Config) ->
{ok, rabbit_mgmt_cors:set_headers(Req, ?MODULE), #context{}}.
variances(Req, Context) ->
{[<<"accept-encoding">>, <<"origin">>], Req, Context}.
content_types_provided(ReqData, Context) ->
{[{<<"application/json">>, to_json}], ReqData, Context}.
resource_exists(ReqData, Context) ->
{case basic(ReqData) of
not_found -> false;
_ -> true
end, ReqData, Context}.
to_json(ReqData, Context) ->
rabbit_mgmt_util:reply_list(
rabbit_mgmt_util:filter_vhost(basic(ReqData), ReqData, Context),
["priority"], ReqData, Context).
is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
%%--------------------------------------------------------------------
basic(ReqData) ->
case rabbit_mgmt_util:vhost(ReqData) of
not_found -> not_found;
none -> rabbit_policy:list_op();
VHost -> rabbit_policy:list_op(VHost)
end.