~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy

« back to all changes in this revision

Viewing changes to plugins-src/rabbitmq-management/src/rabbit_mgmt_wm_parameters.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2012-11-19 11:42:31 UTC
  • mfrom: (0.2.18) (0.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20121119114231-hvapkn4akng09etr
Tags: 3.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%   The contents of this file are subject to the Mozilla Public License
 
2
%%   Version 1.1 (the "License"); you may not use this file except in
 
3
%%   compliance with the License. You may obtain a copy of the License at
 
4
%%   http://www.mozilla.org/MPL/
 
5
%%
 
6
%%   Software distributed under the License is distributed on an "AS IS"
 
7
%%   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
8
%%   License for the specific language governing rights and limitations
 
9
%%   under the License.
 
10
%%
 
11
%%   The Original Code is RabbitMQ Management Plugin.
 
12
%%
 
13
%%   The Initial Developer of the Original Code is VMware, Inc.
 
14
%%   Copyright (c) 2010-2012 VMware, Inc.  All rights reserved.
 
15
%%
 
16
 
 
17
-module(rabbit_mgmt_wm_parameters).
 
18
 
 
19
-export([init/1, to_json/2, content_types_provided/2, is_authorized/2,
 
20
         resource_exists/2, basic/1]).
 
21
 
 
22
-include("rabbit_mgmt.hrl").
 
23
-include_lib("webmachine/include/webmachine.hrl").
 
24
-include_lib("rabbit_common/include/rabbit.hrl").
 
25
 
 
26
%%--------------------------------------------------------------------
 
27
 
 
28
init(_Config) -> {ok, #context{}}.
 
29
 
 
30
content_types_provided(ReqData, Context) ->
 
31
   {[{"application/json", to_json}], ReqData, Context}.
 
32
 
 
33
resource_exists(ReqData, Context) ->
 
34
    {case basic(ReqData) of
 
35
         not_found -> false;
 
36
         _         -> true
 
37
     end, ReqData, Context}.
 
38
 
 
39
to_json(ReqData, Context) ->
 
40
    rabbit_mgmt_util:reply_list(basic(ReqData), ReqData, Context).
 
41
 
 
42
is_authorized(ReqData, Context) ->
 
43
    rabbit_mgmt_util:is_authorized_admin(ReqData, Context).
 
44
 
 
45
%%--------------------------------------------------------------------
 
46
 
 
47
basic(ReqData) ->
 
48
    Raw = case rabbit_mgmt_util:id(component, ReqData) of
 
49
              none -> rabbit_runtime_parameters:list();
 
50
              Name -> case rabbit_mgmt_util:vhost(ReqData) of
 
51
                          none      -> rabbit_runtime_parameters:list_strict(
 
52
                                         Name);
 
53
                          not_found -> not_found;
 
54
                          VHost     -> rabbit_runtime_parameters:list_strict(
 
55
                                         VHost, Name)
 
56
                      end
 
57
          end,
 
58
    case Raw of
 
59
        not_found -> not_found;
 
60
        _         -> [rabbit_mgmt_format:parameter(P) || P <- Raw]
 
61
    end.