refactor(alias_enrichment): rename `enrich_clientid_alias` -> `enrich_with_aliases` and `clientid_enrichment_module` ->`alias_enrichment_module`

Addresses
https://github.com/emqx/emqx-enterprise/pull/1535#discussion_r1022132136

Since it enriches client information with more than just clientid
alias.
This commit is contained in:
Thales Macedo Garitezi 2022-11-16 10:00:47 -03:00
parent 40ae1fac80
commit 5aa6b6dbb6
3 changed files with 12 additions and 12 deletions

View File

@ -852,11 +852,11 @@ end}.
{datatype, string} {datatype, string}
]}. ]}.
%% @doc Specify a module that defines the `enrich_clientid_alias/2' %% @doc Specify a module that defines the `enrich_with_aliases/2'
%% function. This function will be used to enrich the client/channel %% function. This function will be used to enrich the client/channel
%% information with clientid and/or common name aliases (or other %% information with clientid and/or common name aliases (or other
%% enrichments the module may implement). %% enrichments the module may implement).
{mapping, "clientid_enrichment_module", "emqx.clientid_enrichment_module", [ {mapping, "alias_enrichment_module", "emqx.alias_enrichment_module", [
{datatype, atom} {datatype, atom}
]}. ]}.

View File

@ -26,7 +26,7 @@
]). ]).
%% internal exports for ad-hoc debugging. %% internal exports for ad-hoc debugging.
-export([ set_clientid_enrichment_module/0 -export([ set_alias_enrichment_module/0
, set_special_auth_module/0 , set_special_auth_module/0
]). ]).
@ -54,7 +54,7 @@ start(_Type, _Args) ->
ok = emqx_plugins:init(), ok = emqx_plugins:init(),
_ = emqx_plugins:load(), _ = emqx_plugins:load(),
_ = start_ce_modules(), _ = start_ce_modules(),
set_clientid_enrichment_module(), set_alias_enrichment_module(),
_ = set_special_auth_module(), _ = set_special_auth_module(),
register(emqx, self()), register(emqx, self()),
print_vsn(), print_vsn(),
@ -85,14 +85,14 @@ start_ce_modules() ->
ok. ok.
-endif. -endif.
set_clientid_enrichment_module() -> set_alias_enrichment_module() ->
case emqx:get_env(clientid_enrichment_module) of case emqx:get_env(alias_enrichment_module) of
undefined -> undefined ->
ok; ok;
Mod -> Mod ->
case erlang:function_exported(Mod, enrich_clientid_alias, 2) of case erlang:function_exported(Mod, enrich_with_aliases, 2) of
true -> true ->
persistent_term:put(clientid_enrichment_module, Mod); persistent_term:put(alias_enrichment_module, Mod);
false -> false ->
ok ok
end end

View File

@ -313,7 +313,7 @@ handle_in(?CONNECT_PACKET(ConnPkt) = Packet, Channel) ->
fun set_log_meta/2, fun set_log_meta/2,
fun check_banned/2, fun check_banned/2,
fun count_flapping_event/2, fun count_flapping_event/2,
fun enrich_clientid_alias/2, fun enrich_with_aliases/2,
fun auth_connect/2 fun auth_connect/2
], ConnPkt, Channel#channel{conn_state = connecting}) of ], ConnPkt, Channel#channel{conn_state = connecting}) of
{ok, NConnPkt, NChannel = #channel{clientinfo = ClientInfo}} -> {ok, NConnPkt, NChannel = #channel{clientinfo = ClientInfo}} ->
@ -1363,12 +1363,12 @@ check_banned(_ConnPkt, #channel{clientinfo = ClientInfo = #{zone := Zone}}) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Enrich ClientID Alias %% Enrich ClientID Alias
enrich_clientid_alias(Packet, Channel) -> enrich_with_aliases(Packet, Channel) ->
case persistent_term:get(clientid_enrichment_module, undefined) of case persistent_term:get(alias_enrichment_module, undefined) of
undefined -> undefined ->
{ok, Channel}; {ok, Channel};
Mod -> Mod ->
Mod:enrich_clientid_alias(Packet, Channel) Mod:enrich_with_aliases(Packet, Channel)
end. end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------