|
| 1 | +%%%------------------------------------------------------------------- |
| 2 | +%%% @author dmj |
| 3 | +%%% @copyright (C) 2016, Telefonica Investigación y Desarrollo, S.A.U |
| 4 | +%%% @doc |
| 5 | +%%% |
| 6 | +%%% This file is part of RabbitMQ ACL Topic plugin. |
| 7 | +%%% |
| 8 | +%%% RabbitMQ ACL Topic plugin is free software: you can redistribute it and/or |
| 9 | +%%% modify it under the terms of the GNU Affero General Public License as |
| 10 | +%%% published by the Free Software Foundation, either version 3 of the License, |
| 11 | +%%% or (at your option) any later version. |
| 12 | +%%% |
| 13 | +%%% RabbitMQ ACL Topic plugin is distributed in the hope that it will be useful, |
| 14 | +%%% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | +%%% See the GNU Affero General Public License for more details. |
| 17 | +%%% |
| 18 | +%%% You should have received a copy of the GNU Affero General Public |
| 19 | +%%% License along with RabbitMQ ACL Topic plugin. |
| 20 | +%%% If not, see http://www.gnu.org/licenses/. |
| 21 | +%%% |
| 22 | +%%% For those usages not covered by the GNU Affero General Public License |
| 23 | +%%% please contact with::[email protected] |
| 24 | +%%% |
| 25 | +%%% @end |
| 26 | +%%% Created : 28. dic 2016 17:36 |
| 27 | +%%%------------------------------------------------------------------- |
| 28 | +-module(aclstore). |
| 29 | +-behaviour(application). |
| 30 | +-author("dmj"). |
| 31 | + |
| 32 | +%% API |
| 33 | +-export([start/2, stop/1, install/1]). |
| 34 | +-export([add_permission/3]). |
| 35 | + |
| 36 | +-record(aclstore_record, { |
| 37 | + user, |
| 38 | + topic, |
| 39 | + permission |
| 40 | +}). |
| 41 | + |
| 42 | +start(normal, []) -> |
| 43 | + mnesia:wait_for_tables([aclstore_record], 5000), |
| 44 | + aclstore_sup:start_link(). |
| 45 | + |
| 46 | +stop(_) -> ok. |
| 47 | + |
| 48 | +install(Nodes) -> |
| 49 | + ok = mnesia:create_schema(Nodes), |
| 50 | + rpc:multicall(Nodes, application, start, [mnesia]), |
| 51 | + mnesia:create_table(aclstore_record, |
| 52 | + [{attributes, record_info(fields, aclstore_record)}, |
| 53 | + {index, [#aclstore_record.topic]}, |
| 54 | + {disc_copies, Nodes}, |
| 55 | + {type, set}]), |
| 56 | + rpc:multicall(Nodes, application, stop, [mnesia]). |
| 57 | + |
| 58 | +add_permission(User, Topic, Permission) -> |
| 59 | + F = fun() -> |
| 60 | + mnesia:write(#aclstore_record{ |
| 61 | + user= User, |
| 62 | + topic = Topic, |
| 63 | + permission = Permission |
| 64 | + }) |
| 65 | + end, |
| 66 | + mnesia:activity(transaction, F). |
0 commit comments