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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2012-06-22 17:48:28 UTC
  • mfrom: (0.2.16) (0.1.28 sid)
  • Revision ID: package-import@ubuntu.com-20120622174828-1t2dts9myai6ogqo
Tags: 2.8.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
%%   The Original Code is RabbitMQ Management Plugin.
12
12
%%
13
13
%%   The Initial Developer of the Original Code is VMware, Inc.
14
 
%%   Copyright (c) 2010-2011 VMware, Inc.  All rights reserved.
 
14
%%   Copyright (c) 2010-2012 VMware, Inc.  All rights reserved.
15
15
%%
16
16
 
17
17
-module(rabbit_mgmt_wm_definitions).
20
20
-export([content_types_accepted/2, allowed_methods/2, accept_json/2]).
21
21
-export([post_is_create/2, create_path/2, accept_multipart/2]).
22
22
 
 
23
-export([apply_defs/3]).
 
24
 
23
25
-import(rabbit_misc, [pget/2]).
24
26
 
25
27
-include("rabbit_mgmt.hrl").
100
102
%%--------------------------------------------------------------------
101
103
 
102
104
accept(Body, ReqData, Context) ->
103
 
    rabbit_mgmt_util:with_decode(
104
 
      [users, vhosts, permissions, queues, exchanges, bindings],
105
 
      Body, ReqData, Context,
106
 
      fun([Users, VHosts, Permissions, Queues, Exchanges, Bindings], _) ->
107
 
              try
108
 
                  for_all(Users,       fun add_user/1),
109
 
                  for_all(VHosts,      fun add_vhost/1),
110
 
                  for_all(Permissions, fun add_permission/1),
111
 
                  for_all(Queues,      fun add_queue/1),
112
 
                  for_all(Exchanges,   fun add_exchange/1),
113
 
                  for_all(Bindings,    fun add_binding/1),
114
 
                  {true, ReqData, Context}
115
 
              catch
116
 
                  exit:E ->
117
 
                      rabbit_mgmt_util:bad_request(E, ReqData, Context)
118
 
              end
119
 
      end).
 
105
    apply_defs(Body, fun() -> {true, ReqData, Context} end,
 
106
               fun(E) -> rabbit_mgmt_util:bad_request(E, ReqData, Context) end).
 
107
 
 
108
apply_defs(Body, SuccessFun, ErrorFun) ->
 
109
    case rabbit_mgmt_util:decode(
 
110
           [users, vhosts, permissions, queues, exchanges, bindings], Body) of
 
111
        {error, E} ->
 
112
            ErrorFun(E);
 
113
        {ok, [Users, VHosts, Permissions, Queues, Exchanges, Bindings], _} ->
 
114
            try
 
115
                for_all(Users,       fun add_user/1),
 
116
                for_all(VHosts,      fun add_vhost/1),
 
117
                for_all(Permissions, fun add_permission/1),
 
118
                for_all(Queues,      fun add_queue/1),
 
119
                for_all(Exchanges,   fun add_exchange/1),
 
120
                for_all(Bindings,    fun add_binding/1),
 
121
                SuccessFun()
 
122
            catch {error, E} -> ErrorFun(E);
 
123
                  exit:E     -> ErrorFun(E)
 
124
            end
 
125
    end.
120
126
 
121
127
get_part(Name, Parts) ->
122
128
    Filtered = [Value || {N, _Meta, Value} <- Parts, N == Name],