refactor(auth): rename functions from may_xx to maybe_xx
This commit is contained in:
parent
3dcccc0b33
commit
0b432a6a77
|
@ -266,8 +266,9 @@ do_post_config_update({move_authenticator, ChainName, AuthenticatorID, Position}
|
||||||
move_authenticator(ChainName, AuthenticatorID, Position).
|
move_authenticator(ChainName, AuthenticatorID, Position).
|
||||||
|
|
||||||
check_config(Config) ->
|
check_config(Config) ->
|
||||||
#{authentication := CheckedConfig} = hocon_schema:check_plain(emqx_authentication,
|
#{authentication := CheckedConfig} =
|
||||||
#{<<"authentication">> => Config}, #{nullable => true, atom_key => true}),
|
hocon_schema:check_plain(?MODULE, #{<<"authentication">> => Config},
|
||||||
|
#{nullable => true, atom_key => true}),
|
||||||
CheckedConfig.
|
CheckedConfig.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
@ -476,7 +477,7 @@ handle_call({delete_chain, Name}, _From, State) ->
|
||||||
[#chain{authenticators = Authenticators}] ->
|
[#chain{authenticators = Authenticators}] ->
|
||||||
_ = [do_delete_authenticator(Authenticator) || Authenticator <- Authenticators],
|
_ = [do_delete_authenticator(Authenticator) || Authenticator <- Authenticators],
|
||||||
true = ets:delete(?CHAINS_TAB, Name),
|
true = ets:delete(?CHAINS_TAB, Name),
|
||||||
reply(ok, may_unhook(State))
|
reply(ok, maybe_unhook(State))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_call({lookup_chain, Name}, _From, State) ->
|
handle_call({lookup_chain, Name}, _From, State) ->
|
||||||
|
@ -506,7 +507,7 @@ handle_call({create_authenticator, ChainName, Config}, _From, #{providers := Pro
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Reply = update_chain(ChainName, UpdateFun),
|
Reply = update_chain(ChainName, UpdateFun),
|
||||||
reply(Reply, may_hook(State));
|
reply(Reply, maybe_hook(State));
|
||||||
|
|
||||||
handle_call({delete_authenticator, ChainName, AuthenticatorID}, _From, State) ->
|
handle_call({delete_authenticator, ChainName, AuthenticatorID}, _From, State) ->
|
||||||
UpdateFun =
|
UpdateFun =
|
||||||
|
@ -521,7 +522,7 @@ handle_call({delete_authenticator, ChainName, AuthenticatorID}, _From, State) ->
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Reply = update_chain(ChainName, UpdateFun),
|
Reply = update_chain(ChainName, UpdateFun),
|
||||||
reply(Reply, may_unhook(State));
|
reply(Reply, maybe_unhook(State));
|
||||||
|
|
||||||
handle_call({update_authenticator, ChainName, AuthenticatorID, Config}, _From, State) ->
|
handle_call({update_authenticator, ChainName, AuthenticatorID, Config}, _From, State) ->
|
||||||
UpdateFun =
|
UpdateFun =
|
||||||
|
@ -726,30 +727,30 @@ global_chain(stomp) ->
|
||||||
global_chain(_) ->
|
global_chain(_) ->
|
||||||
'unknown:global'.
|
'unknown:global'.
|
||||||
|
|
||||||
may_hook(#{hooked := false} = State) ->
|
maybe_hook(#{hooked := false} = State) ->
|
||||||
case lists:any(fun(#chain{authenticators = []}) -> false;
|
case lists:any(fun(#chain{authenticators = []}) -> false;
|
||||||
(_) -> true
|
(_) -> true
|
||||||
end, ets:tab2list(?CHAINS_TAB)) of
|
end, ets:tab2list(?CHAINS_TAB)) of
|
||||||
true ->
|
true ->
|
||||||
_ = emqx:hook('client.authenticate', {emqx_authentication, authenticate, []}),
|
_ = emqx:hook('client.authenticate', {?MODULE, authenticate, []}),
|
||||||
State#{hooked => true};
|
State#{hooked => true};
|
||||||
false ->
|
false ->
|
||||||
State
|
State
|
||||||
end;
|
end;
|
||||||
may_hook(State) ->
|
maybe_hook(State) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
may_unhook(#{hooked := true} = State) ->
|
maybe_unhook(#{hooked := true} = State) ->
|
||||||
case lists:all(fun(#chain{authenticators = []}) -> true;
|
case lists:all(fun(#chain{authenticators = []}) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
end, ets:tab2list(?CHAINS_TAB)) of
|
end, ets:tab2list(?CHAINS_TAB)) of
|
||||||
true ->
|
true ->
|
||||||
_ = emqx:unhook('client.authenticate', {emqx_authentication, authenticate, []}),
|
_ = emqx:unhook('client.authenticate', {?MODULE, authenticate, []}),
|
||||||
State#{hooked => false};
|
State#{hooked => false};
|
||||||
false ->
|
false ->
|
||||||
State
|
State
|
||||||
end;
|
end;
|
||||||
may_unhook(State) ->
|
maybe_unhook(State) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
do_create_authenticator(ChainName, AuthenticatorID, #{enable := Enable} = Config, Providers) ->
|
do_create_authenticator(ChainName, AuthenticatorID, #{enable := Enable} = Config, Providers) ->
|
||||||
|
@ -773,7 +774,7 @@ do_create_authenticator(ChainName, AuthenticatorID, #{enable := Enable} = Config
|
||||||
do_delete_authenticator(#authenticator{provider = Provider, state = State}) ->
|
do_delete_authenticator(#authenticator{provider = Provider, state = State}) ->
|
||||||
_ = Provider:destroy(State),
|
_ = Provider:destroy(State),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
replace_authenticator(ID, Authenticator, Authenticators) ->
|
replace_authenticator(ID, Authenticator, Authenticators) ->
|
||||||
lists:keyreplace(ID, #authenticator.id, Authenticators, Authenticator).
|
lists:keyreplace(ID, #authenticator.id, Authenticators, Authenticator).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue