Skip to content

Commit 88234f2

Browse files
committed
Initial version
0 parents  commit 88234f2

7 files changed

+181
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
*.beam
3+
logs/
4+
.DS_Store
5+
.rebar/

Emakefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{["src/*", "test/*"],
2+
[{i,"include"}, {outdir, "ebin"}]}.

ebin/topicaclplugin.app

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{application,topicaclplugin,
2+
[{description,"Rabbit MQ Plugin for adding ACL permissions for topics"},
3+
{vsn,"1.0.0"},
4+
{registered,[]},
5+
{applications,[kernel,stdlib,mnesia]},
6+
{mod,{topicaclplugin_app,[]}},
7+
{env,[]},
8+
{modules,[aclstore,aclstore_sup]}]}.

src/aclstore.erl

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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).

src/aclstore_sup.erl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_sup).
29+
-author("dmj").
30+
-behaviour(supervisor).
31+
32+
%% API
33+
-export([start_link/0, init/1]).
34+
35+
start_link() ->
36+
supervisor:start_link(?MODULE, []).
37+
38+
init([]) ->
39+
{ok, {{one_for_one, 1, 1}, []}}.
40+

test/file-load_SUITE.erl

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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('file-load_SUITE').
29+
-author("dmj").
30+
31+
-include_lib("common_test/include/ct.hrl").
32+
-export([init_per_suite/1, end_per_suite/1, all/0,
33+
init_per_testcase/2, end_per_testcase/2]).
34+
-export([add_permission/1]).
35+
36+
all() -> [add_permission].
37+
38+
init_per_suite(Config) ->
39+
Priv = ?config(priv_dir, Config),
40+
application:set_env(mnesia, dir, Priv),
41+
aclstore:install([node()]),
42+
application:start(mnesia),
43+
application:start(aclstore),
44+
Config.
45+
46+
end_per_suite(_Config) ->
47+
application:stop(mnesia),
48+
ok.
49+
50+
init_per_testcase(add_permission, Config) ->
51+
Config.
52+
53+
end_per_testcase(_, _Config) ->
54+
ok.
55+
56+
add_permission(_Config) ->
57+
ok = aclstore:add_permission("johndoe", "root/subroot/+", "write").

topicaclplugin.spec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{alias, root, "./test/"}.
2+
{logdir, "./logs/"}.
3+
{suites, root, all}.

0 commit comments

Comments
 (0)