Better report errors in acl.conf (#2065)
This commit is contained in:
parent
7d9e350bbe
commit
97474171d0
|
@ -156,16 +156,19 @@ handle_call({register_mod, Type, Mod, Opts, Seq}, _From, State) ->
|
||||||
reply(case lists:keymember(Mod, 1, Mods) of
|
reply(case lists:keymember(Mod, 1, Mods) of
|
||||||
true -> {error, already_exists};
|
true -> {error, already_exists};
|
||||||
false ->
|
false ->
|
||||||
case catch Mod:init(Opts) of
|
try
|
||||||
|
case Mod:init(Opts) of
|
||||||
{ok, ModState} ->
|
{ok, ModState} ->
|
||||||
NewMods = lists:sort(fun({_, _, Seq1}, {_, _, Seq2}) ->
|
NewMods = lists:sort(fun({_, _, Seq1}, {_, _, Seq2}) ->
|
||||||
Seq1 >= Seq2
|
Seq1 >= Seq2
|
||||||
end, [{Mod, ModState, Seq} | Mods]),
|
end, [{Mod, ModState, Seq} | Mods]),
|
||||||
ets:insert(?TAB, {tab_key(Type), NewMods}), ok;
|
ets:insert(?TAB, {tab_key(Type), NewMods}),
|
||||||
{error, Error} ->
|
ok
|
||||||
{error, Error};
|
end
|
||||||
{'EXIT', Reason} ->
|
catch
|
||||||
{error, Reason}
|
_:Error ->
|
||||||
|
emqx_logger:error("[AccessControl] Failed to init ~s: ~p", [Mod, Error]),
|
||||||
|
{error, Error}
|
||||||
end
|
end
|
||||||
end, State);
|
end, State);
|
||||||
|
|
||||||
|
|
|
@ -44,11 +44,7 @@ compile({A, Who, Access, Topic}) when ?ALLOW_DENY(A), ?PUBSUB(Access), is_binary
|
||||||
{A, compile(who, Who), Access, [compile(topic, Topic)]};
|
{A, compile(who, Who), Access, [compile(topic, Topic)]};
|
||||||
|
|
||||||
compile({A, Who, Access, TopicFilters}) when ?ALLOW_DENY(A), ?PUBSUB(Access) ->
|
compile({A, Who, Access, TopicFilters}) when ?ALLOW_DENY(A), ?PUBSUB(Access) ->
|
||||||
{A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]};
|
{A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]}.
|
||||||
|
|
||||||
compile(Rule) ->
|
|
||||||
emqx_logger:error("[ACCESS_RULE] Malformed rule: ~p", [Rule]),
|
|
||||||
{error, bad_rule}.
|
|
||||||
|
|
||||||
compile(who, all) ->
|
compile(who, all) ->
|
||||||
all;
|
all;
|
||||||
|
|
|
@ -64,8 +64,6 @@ load_rules_from_file(AclFile) ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
filter(_PubSub, {error, _}) ->
|
|
||||||
false;
|
|
||||||
filter(_PubSub, {allow, all}) ->
|
filter(_PubSub, {allow, all}) ->
|
||||||
true;
|
true;
|
||||||
filter(_PubSub, {deny, all}) ->
|
filter(_PubSub, {deny, all}) ->
|
||||||
|
|
|
@ -355,8 +355,7 @@ compile_rule(_) ->
|
||||||
{deny, all, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
|
{deny, all, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
|
||||||
compile({deny, all, subscribe, ["$SYS/#", "#"]}),
|
compile({deny, all, subscribe, ["$SYS/#", "#"]}),
|
||||||
{allow, all} = compile({allow, all}),
|
{allow, all} = compile({allow, all}),
|
||||||
{deny, all} = compile({deny, all}),
|
{deny, all} = compile({deny, all}).
|
||||||
{error, bad_rule} = compile({test, malformed}).
|
|
||||||
|
|
||||||
match_rule(_) ->
|
match_rule(_) ->
|
||||||
User = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{127,0,0,1}, 2948}},
|
User = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{127,0,0,1}, 2948}},
|
||||||
|
|
Loading…
Reference in New Issue