diff --git a/priv/emqx.schema b/priv/emqx.schema index 7c089917c..7ca1f06ff 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -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}. diff --git a/src/emqx_mod_acl_internal.erl b/src/emqx_mod_acl_internal.erl index 770f90c83..0d24ddb9f 100644 --- a/src/emqx_mod_acl_internal.erl +++ b/src/emqx_mod_acl_internal.erl @@ -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". diff --git a/test/emqx_acl_cache_SUITE.erl b/test/emqx_acl_cache_SUITE.erl index bd04961c6..6d314598c 100644 --- a/test/emqx_acl_cache_SUITE.erl +++ b/test/emqx_acl_cache_SUITE.erl @@ -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 diff --git a/test/mqtt_protocol_v5_SUITE.erl b/test/mqtt_protocol_v5_SUITE.erl index b67adb9d1..50fc9c04d 100644 --- a/test/mqtt_protocol_v5_SUITE.erl +++ b/test/mqtt_protocol_v5_SUITE.erl @@ -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},