improve: module_acl_internal load/unload api (#3706)
This commit is contained in:
parent
90b33b044d
commit
edcbdcce87
|
@ -1969,7 +1969,7 @@ end}.
|
|||
{datatype, string}
|
||||
]}.
|
||||
|
||||
{translation, "emqx.modules", fun(Conf) ->
|
||||
{translation, "emqx.modules", fun(Conf, _, Conf1) ->
|
||||
Subscriptions = fun() ->
|
||||
List = cuttlefish_variable:filter_by_prefix("module.subscription", Conf),
|
||||
TopicList = [{N, Topic}|| {[_,"subscription",N,"topic"], Topic} <- List],
|
||||
|
@ -1998,7 +1998,7 @@ end}.
|
|||
[{emqx_mod_rewrite, Rewrites()}],
|
||||
[{emqx_mod_topic_metrics, []}],
|
||||
[{emqx_mod_delayed, []}],
|
||||
[{emqx_mod_acl_internal, []}]
|
||||
[{emqx_mod_acl_internal, [{acl_file, cuttlefish:conf_get("acl_file", Conf1)}]}]
|
||||
])
|
||||
end}.
|
||||
|
||||
|
|
|
@ -40,19 +40,19 @@
|
|||
%% API
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
load(_Env) ->
|
||||
Rules = rules_from_file(emqx:get_env(acl_file)),
|
||||
load(Env) ->
|
||||
Rules = rules_from_file(proplists:get_value(acl_file, Env)),
|
||||
emqx_hooks:add('client.check_acl', {?MODULE, check_acl, [Rules]}, -1).
|
||||
|
||||
unload(_Env) ->
|
||||
emqx_hooks:del('client.check_acl', {?MODULE, check_acl}).
|
||||
|
||||
reload(_Env) ->
|
||||
reload(Env) ->
|
||||
emqx_acl_cache:is_enabled() andalso (
|
||||
lists:foreach(
|
||||
fun(Pid) -> erlang:send(Pid, clean_acl_cache) end,
|
||||
emqx_cm:all_channels())),
|
||||
unload([]), load([]).
|
||||
unload(Env), load(Env).
|
||||
|
||||
description() ->
|
||||
"EMQ X Internal ACL Module".
|
||||
|
|
|
@ -83,9 +83,8 @@ t_reload_aclfile_and_cleanall(Config) ->
|
|||
Path = filename:join([testdir(proplists:get_value(data_dir, Config)), "acl2.conf"]),
|
||||
ok = file:write_file(Path, <<"{deny, all}.">>),
|
||||
OldPath = emqx:get_env(acl_file),
|
||||
application:set_env(emqx, acl_file, Path),
|
||||
|
||||
emqx_mod_acl_internal:reload([]),
|
||||
% application:set_env(emqx, acl_file, Path),
|
||||
emqx_mod_acl_internal:reload([{acl_file, Path}]),
|
||||
|
||||
?assert(length(gen_server:call(ClientPid, list_acl_cache)) == 0),
|
||||
{ok, PktId2} = emqtt:publish(Client, <<"t1">>, <<"{\"x\":1}">>, qos1),
|
||||
|
@ -99,7 +98,7 @@ t_reload_aclfile_and_cleanall(Config) ->
|
|||
end,
|
||||
application:set_env(emqx, acl_file, OldPath),
|
||||
file:delete(Path),
|
||||
emqx_mod_acl_internal:reload([]),
|
||||
emqx_mod_acl_internal:reload([{acl_file, OldPath}]),
|
||||
emqtt:stop(Client).
|
||||
|
||||
%% @private
|
||||
|
|
|
@ -181,8 +181,8 @@ t_batch_subscribe(_) ->
|
|||
application:set_env(emqx, enable_acl_cache, false),
|
||||
TempAcl = emqx_ct_helpers:deps_path(emqx, "test/emqx_access_SUITE_data/acl_temp.conf"),
|
||||
file:write_file(TempAcl, "{deny, {client, \"batch_test\"}, subscribe, [\"t1\", \"t2\", \"t3\"]}.\n"),
|
||||
application:set_env(emqx, acl_file, TempAcl),
|
||||
emqx_mod_acl_internal:reload([]),
|
||||
timer:sleep(10),
|
||||
emqx_mod_acl_internal:reload([{acl_file, TempAcl}]),
|
||||
{ok, _, [?RC_NOT_AUTHORIZED,
|
||||
?RC_NOT_AUTHORIZED,
|
||||
?RC_NOT_AUTHORIZED]} = emqtt:subscribe(Client, [{<<"t1">>, qos1},
|
||||
|
|
Loading…
Reference in New Issue