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
|
||||
true -> {error, already_exists};
|
||||
false ->
|
||||
case catch Mod:init(Opts) of
|
||||
{ok, ModState} ->
|
||||
NewMods = lists:sort(fun({_, _, Seq1}, {_, _, Seq2}) ->
|
||||
Seq1 >= Seq2
|
||||
end, [{Mod, ModState, Seq} | Mods]),
|
||||
ets:insert(?TAB, {tab_key(Type), NewMods}), ok;
|
||||
{error, Error} ->
|
||||
{error, Error};
|
||||
{'EXIT', Reason} ->
|
||||
{error, Reason}
|
||||
try
|
||||
case Mod:init(Opts) of
|
||||
{ok, ModState} ->
|
||||
NewMods = lists:sort(fun({_, _, Seq1}, {_, _, Seq2}) ->
|
||||
Seq1 >= Seq2
|
||||
end, [{Mod, ModState, Seq} | Mods]),
|
||||
ets:insert(?TAB, {tab_key(Type), NewMods}),
|
||||
ok
|
||||
end
|
||||
catch
|
||||
_:Error ->
|
||||
emqx_logger:error("[AccessControl] Failed to init ~s: ~p", [Mod, Error]),
|
||||
{error, Error}
|
||||
end
|
||||
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)]};
|
||||
|
||||
compile({A, Who, Access, TopicFilters}) when ?ALLOW_DENY(A), ?PUBSUB(Access) ->
|
||||
{A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]};
|
||||
|
||||
compile(Rule) ->
|
||||
emqx_logger:error("[ACCESS_RULE] Malformed rule: ~p", [Rule]),
|
||||
{error, bad_rule}.
|
||||
{A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]}.
|
||||
|
||||
compile(who, all) ->
|
||||
all;
|
||||
|
|
|
@ -64,8 +64,6 @@ load_rules_from_file(AclFile) ->
|
|||
{error, Reason}
|
||||
end.
|
||||
|
||||
filter(_PubSub, {error, _}) ->
|
||||
false;
|
||||
filter(_PubSub, {allow, all}) ->
|
||||
true;
|
||||
filter(_PubSub, {deny, all}) ->
|
||||
|
|
|
@ -355,8 +355,7 @@ compile_rule(_) ->
|
|||
{deny, all, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
|
||||
compile({deny, all, subscribe, ["$SYS/#", "#"]}),
|
||||
{allow, all} = compile({allow, all}),
|
||||
{deny, all} = compile({deny, all}),
|
||||
{error, bad_rule} = compile({test, malformed}).
|
||||
{deny, all} = compile({deny, all}).
|
||||
|
||||
match_rule(_) ->
|
||||
User = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{127,0,0,1}, 2948}},
|
||||
|
|
Loading…
Reference in New Issue