chore(dialyzer): fix dialyzer error

This commit is contained in:
Rory Z 2021-06-16 11:40:13 +08:00 committed by Shawn
parent bbf6b4e64e
commit 536c7256da
11 changed files with 37 additions and 38 deletions

View File

@ -198,9 +198,7 @@ hook(HookPoint, Action) ->
hook(HookPoint, Action, Priority) when is_integer(Priority) ->
emqx_hooks:add(HookPoint, Action, Priority);
hook(HookPoint, Action, Filter) when is_function(Filter); is_tuple(Filter) ->
emqx_hooks:add(HookPoint, Action, Filter);
hook(HookPoint, Action, InitArgs) when is_list(InitArgs) ->
emqx_hooks:add(HookPoint, Action, InitArgs).
emqx_hooks:add(HookPoint, Action, Filter).
-spec(hook(emqx_hooks:hookpoint(), emqx_hooks:action(), emqx_hooks:filter(), integer())
-> ok | {error, already_exists}).

View File

@ -41,8 +41,8 @@ start(_StartType, _StartArgs) ->
{ok, Sup}.
prep_stop(State) ->
emqx:unhook('client.authenticate', fun emqx_auth_ldap:check/3),
emqx:unhook('client.check_acl', fun emqx_acl_ldap:check_acl/5),
emqx:unhook('client.authenticate',{emqx_auth_ldap, check}),
emqx:unhook('client.check_acl', {emqx_acl_ldap, check_acl}),
State.
stop(_State) ->
@ -51,12 +51,12 @@ stop(_State) ->
load_auth_hook(DeviceDn) ->
ok = emqx_auth_ldap:register_metrics(),
Params = maps:from_list(DeviceDn),
emqx:hook('client.authenticate', fun emqx_auth_ldap:check/3, [Params#{pool => ?APP}]).
emqx:hook('client.authenticate', {emqx_auth_ldap, check, [Params#{pool => ?APP}]}).
load_acl_hook(DeviceDn) ->
ok = emqx_acl_ldap:register_metrics(),
Params = maps:from_list(DeviceDn),
emqx:hook('client.check_acl', fun emqx_acl_ldap:check_acl/5 , [Params#{pool => ?APP}]).
emqx:hook('client.check_acl', {emqx_acl_ldap, check_acl, [Params#{pool => ?APP}]}).
if_enabled(Cfgs, Fun) ->
case get_env(Cfgs) of

View File

@ -42,8 +42,8 @@ start(_StartType, _StartArgs) ->
{ok, Sup}.
prep_stop(State) ->
emqx:unhook('client.authenticate', fun emqx_auth_mnesia:check/3),
emqx:unhook('client.check_acl', fun emqx_acl_mnesia:check_acl/5),
emqx:unhook('client.authenticate', {emqx_auth_mnesia, check}),
emqx:unhook('client.check_acl', {emqx_acl_mnesia, check_acl}),
emqx_ctl:unregister_command(clientid),
emqx_ctl:unregister_command(user),
emqx_ctl:unregister_command(acl),
@ -60,9 +60,9 @@ load_auth_hook() ->
Params = #{
hash_type => application:get_env(emqx_auth_mnesia, password_hash, sha256)
},
emqx:hook('client.authenticate', fun emqx_auth_mnesia:check/3, [Params]).
emqx:hook('client.authenticate', {emqx_auth_mnesia, check, [Params]}).
load_acl_hook() ->
ok = emqx_acl_mnesia:init(),
ok = emqx_acl_mnesia:register_metrics(),
emqx:hook('client.check_acl', fun emqx_acl_mnesia:check_acl/5, [#{}]).
emqx:hook('client.check_acl', {emqx_acl_mnesia, check_acl, [#{}]}).

View File

@ -41,8 +41,8 @@ start(_StartType, _StartArgs) ->
{ok, Sup}.
prep_stop(State) ->
ok = emqx:unhook('client.authenticate', fun emqx_auth_mongo:check/3),
ok = emqx:unhook('client.check_acl', fun emqx_acl_mongo:check_acl/5),
ok = emqx:unhook('client.authenticate', {emqx_auth_mongo, check}),
ok = emqx:unhook('client.check_acl', {emqx_acl_mongo, check_acl}),
State.
stop(_State) ->
@ -51,12 +51,13 @@ stop(_State) ->
reg_authmod(AuthQuery) ->
emqx_auth_mongo:register_metrics(),
SuperQuery = r(super_query, application:get_env(?APP, super_query, undefined)),
ok = emqx:hook('client.authenticate', fun emqx_auth_mongo:check/3,
[#{authquery => AuthQuery, superquery => SuperQuery, pool => ?APP}]).
ok = emqx:hook('client.authenticate', {emqx_auth_mongo, check,
[#{authquery => AuthQuery, superquery => SuperQuery, pool => ?APP}]
}).
reg_aclmod(AclQuery) ->
emqx_acl_mongo:register_metrics(),
ok = emqx:hook('client.check_acl', fun emqx_acl_mongo:check_acl/5, [#{aclquery => AclQuery, pool => ?APP}]).
ok = emqx:hook('client.check_acl', {emqx_acl_mongo, check_acl, [#{aclquery => AclQuery, pool => ?APP}]}).
%%--------------------------------------------------------------------
%% Internal functions

View File

@ -42,8 +42,8 @@ start(_StartType, _StartArgs) ->
{ok, Sup}.
prep_stop(State) ->
emqx:unhook('client.authenticate', fun emqx_auth_mysql:check/3),
emqx:unhook('client.check_acl', fun emqx_acl_mysql:check_acl/5),
emqx:unhook('client.authenticate', {emqx_auth_mysql, check}),
emqx:unhook('client.check_acl', {emqx_acl_mysql, check_acl}),
State.
stop(_State) ->
@ -57,11 +57,11 @@ load_auth_hook(AuthQuery) ->
super_query => SuperQuery,
hash_type => HashType,
pool => ?APP},
emqx:hook('client.authenticate', fun emqx_auth_mysql:check/3, [Params]).
emqx:hook('client.authenticate', {emqx_auth_mysql, check, [Params]}).
load_acl_hook(AclQuery) ->
ok = emqx_acl_mysql:register_metrics(),
emqx:hook('client.check_acl', fun emqx_acl_mysql:check_acl/5, [#{acl_query => AclQuery, pool =>?APP}]).
emqx:hook('client.check_acl', {emqx_acl_mysql, check_acl, [#{acl_query => AclQuery, pool =>?APP}]}).
%%--------------------------------------------------------------------
%% Internal function

View File

@ -43,17 +43,17 @@ start(_StartType, _StartArgs) ->
hash_type => HashType,
pool => ?APP},
ok = emqx_auth_pgsql:register_metrics(),
ok = emqx:hook('client.authenticate', fun emqx_auth_pgsql:check/3, [AuthEnv])
ok = emqx:hook('client.authenticate', {emqx_auth_pgsql, check, [AuthEnv]})
end),
if_enabled(acl_query, fun(AclQuery) ->
ok = emqx_acl_pgsql:register_metrics(),
ok = emqx:hook('client.check_acl', fun emqx_acl_pgsql:check_acl/5, [#{acl_query => AclQuery, pool => ?APP}])
ok = emqx:hook('client.check_acl', {emqx_acl_pgsql, check_acl, [#{acl_query => AclQuery, pool => ?APP}]})
end),
{ok, Sup}.
stop(_State) ->
ok = emqx:unhook('client.authenticate', fun emqx_auth_pgsql:check/3),
ok = emqx:unhook('client.check_acl', fun emqx_acl_pgsql:check_acl/5).
ok = emqx:unhook('client.authenticate', {emqx_auth_pgsql, check}),
ok = emqx:unhook('client.check_acl', {emqx_acl_pgsql, check_acl}).
if_enabled(Par, Fun) ->
case application:get_env(?APP, Par) of

View File

@ -33,8 +33,8 @@ start(_StartType, _StartArgs) ->
{ok, Sup}.
stop(_State) ->
emqx:unhook('client.authenticate', fun emqx_auth_redis:check/3),
emqx:unhook('client.check_acl', fun emqx_acl_redis:check_acl/5),
emqx:unhook('client.authenticate', {emqx_auth_redis, check}),
emqx:unhook('client.check_acl', {emqx_acl_redis, check_acl}),
%% Ensure stop cluster pool if the server type is cluster
eredis_cluster:stop_pool(?APP).
@ -50,7 +50,7 @@ load_auth_hook(AuthCmd) ->
type => Type,
pool => ?APP},
ok = emqx_auth_redis:register_metrics(),
emqx:hook('client.authenticate', fun emqx_auth_redis:check/3, [Config]).
emqx:hook('client.authenticate', {emqx_auth_redis, check, [Config]}).
load_acl_hook(AclCmd) ->
{ok, Timeout} = application:get_env(?APP, query_timeout),
@ -60,7 +60,7 @@ load_acl_hook(AclCmd) ->
type => Type,
pool => ?APP},
ok = emqx_acl_redis:register_metrics(),
emqx:hook('client.check_acl', fun emqx_acl_redis:check_acl/5, [Config]).
emqx:hook('client.check_acl', {emqx_acl_redis, check_acl, [Config]}).
if_cmd_enabled(Par, Fun) ->
case application:get_env(?APP, Par) of

View File

@ -85,13 +85,13 @@ mnesia(copy) ->
ok = ekka_mnesia:copy_table(?SERVICE_TYPE_TAB, ram_copies).
enable() ->
case emqx:hook('client.authenticate', fun emqx_authentication:authenticate/1) of
case emqx:hook('client.authenticate', {emqx_authentication, authenticate, []}) of
ok -> ok;
{error, already_exists} -> ok
end.
disable() ->
emqx:unhook('client.authenticate', fun emqx_authentication:authenticate/1),
emqx:unhook('client.authenticate', {emqx_authentication, authenticate}),
ok.
authenticate(#{chain_id := ChainID} = ClientInfo) ->

View File

@ -38,11 +38,11 @@ load(Env) ->
{ok, PskFile} = file:open(get_value(path, Env), [read, raw, binary, read_ahead]),
preload_psks(PskFile, bin(get_value(delimiter, Env))),
_ = file:close(PskFile),
emqx:hook('tls_handshake.psk_lookup', fun ?MODULE:on_psk_lookup/2, []).
emqx:hook('tls_handshake.psk_lookup', {?MODULE, on_psk_lookup, []}).
%% Called when the plugin application stop
unload() ->
emqx:unhook('tls_handshake.psk_lookup', fun ?MODULE:on_psk_lookup/2).
emqx:unhook('tls_handshake.psk_lookup', {?MODULE, on_psk_lookup}).
on_psk_lookup(ClientPSKID, UserState) ->
case ets:lookup(?TAB, ClientPSKID) of

View File

@ -56,13 +56,13 @@
%%--------------------------------------------------------------------
load(Env) ->
_ = emqx:hook('session.subscribed', fun ?MODULE:on_session_subscribed/3, []),
_ = emqx:hook('message.publish', fun ?MODULE:on_message_publish/2, [Env]),
_ = emqx:hook('session.subscribed', {?MODULE, on_session_subscribed, []}),
_ = emqx:hook('message.publish', {?MODULE, on_message_publish, [Env]}),
ok.
unload() ->
emqx:unhook('message.publish', fun ?MODULE:on_message_publish/2),
emqx:unhook('session.subscribed', fun ?MODULE:on_session_subscribed/3).
emqx:unhook('message.publish', {?MODULE, on_message_publish}),
emqx:unhook('session.subscribed', {?MODULE, on_session_subscribed}).
on_session_subscribed(_, _, #{share := ShareName}) when ShareName =/= undefined ->
ok;

View File

@ -26,10 +26,10 @@
]).
load() ->
emqx:hook('client.enhanced_authenticate', fun ?MODULE:check/3, []).
emqx:hook('client.enhanced_authenticate', {?MODULE, check, []}).
unload() ->
emqx:unhook('client.enhanced_authenticate', fun ?MODULE:check/3).
emqx:unhook('client.enhanced_authenticate', {?MODULE, check}).
init() ->
emqx_sasl_scram:init().