From 3dcccc0b332a30c6347f44d2a61d62ddcfb3c27a Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Thu, 16 Sep 2021 09:32:17 +0200 Subject: [PATCH] refactor(authn): call lists:foreach instaed of list comprehension --- apps/emqx_authn/include/emqx_authn.hrl | 5 +++++ apps/emqx_authn/src/emqx_authn_app.erl | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/emqx_authn/include/emqx_authn.hrl b/apps/emqx_authn/include/emqx_authn.hrl index 5eef08012..1c5c00e85 100644 --- a/apps/emqx_authn/include/emqx_authn.hrl +++ b/apps/emqx_authn/include/emqx_authn.hrl @@ -14,6 +14,9 @@ %% limitations under the License. %%-------------------------------------------------------------------- +-ifndef(EMQX_AUTHN_HRL). +-define(EMQX_AUTHN_HRL, true). + -define(APP, emqx_authn). -define(AUTHN, emqx_authentication). @@ -23,3 +26,5 @@ -define(RE_PLACEHOLDER, "\\$\\{[a-z0-9\\-]+\\}"). -define(AUTH_SHARD, emqx_authn_shard). + +-endif. diff --git a/apps/emqx_authn/src/emqx_authn_app.erl b/apps/emqx_authn/src/emqx_authn_app.erl index 4d4a22791..98d53e438 100644 --- a/apps/emqx_authn/src/emqx_authn_app.erl +++ b/apps/emqx_authn/src/emqx_authn_app.erl @@ -45,17 +45,20 @@ stop(_State) -> %%------------------------------------------------------------------------------ add_providers() -> - _ = [?AUTHN:add_provider(AuthNType, Provider) || {AuthNType, Provider} <- providers()], ok. + lists:foreach(fun(AuthNType, Provider}) -> + ?AUTHN:add_provider(AuthNType, Provider) + end, providers()). remove_providers() -> - _ = [?AUTHN:remove_provider(AuthNType) || {AuthNType, _} <- providers()], ok. + lists:foreach(fun({AuthNType, _}) -> + ?AUTHN:remove_provider(AuthNType) + end, providers()). initialize() -> ?AUTHN:initialize_authentication(?GLOBAL, emqx:get_raw_config([authentication], [])), lists:foreach(fun({ListenerID, ListenerConfig}) -> ?AUTHN:initialize_authentication(ListenerID, maps:get(authentication, ListenerConfig, [])) - end, emqx_listeners:list()), - ok. + end, emqx_listeners:list()). providers() -> [ {{'password-based', 'built-in-database'}, emqx_authn_mnesia} @@ -66,4 +69,4 @@ providers() -> , {{'password-based', 'http-server'}, emqx_authn_http} , {jwt, emqx_authn_jwt} , {{scram, 'built-in-database'}, emqx_enhanced_authn_scram_mnesia} - ]. \ No newline at end of file + ].