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:
parent
40ae1fac80
commit
5aa6b6dbb6
|
@ -852,11 +852,11 @@ end}.
|
|||
{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
|
||||
%% information with clientid and/or common name aliases (or other
|
||||
%% enrichments the module may implement).
|
||||
{mapping, "clientid_enrichment_module", "emqx.clientid_enrichment_module", [
|
||||
{mapping, "alias_enrichment_module", "emqx.alias_enrichment_module", [
|
||||
{datatype, atom}
|
||||
]}.
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
]).
|
||||
|
||||
%% internal exports for ad-hoc debugging.
|
||||
-export([ set_clientid_enrichment_module/0
|
||||
-export([ set_alias_enrichment_module/0
|
||||
, set_special_auth_module/0
|
||||
]).
|
||||
|
||||
|
@ -54,7 +54,7 @@ start(_Type, _Args) ->
|
|||
ok = emqx_plugins:init(),
|
||||
_ = emqx_plugins:load(),
|
||||
_ = start_ce_modules(),
|
||||
set_clientid_enrichment_module(),
|
||||
set_alias_enrichment_module(),
|
||||
_ = set_special_auth_module(),
|
||||
register(emqx, self()),
|
||||
print_vsn(),
|
||||
|
@ -85,14 +85,14 @@ start_ce_modules() ->
|
|||
ok.
|
||||
-endif.
|
||||
|
||||
set_clientid_enrichment_module() ->
|
||||
case emqx:get_env(clientid_enrichment_module) of
|
||||
set_alias_enrichment_module() ->
|
||||
case emqx:get_env(alias_enrichment_module) of
|
||||
undefined ->
|
||||
ok;
|
||||
Mod ->
|
||||
case erlang:function_exported(Mod, enrich_clientid_alias, 2) of
|
||||
case erlang:function_exported(Mod, enrich_with_aliases, 2) of
|
||||
true ->
|
||||
persistent_term:put(clientid_enrichment_module, Mod);
|
||||
persistent_term:put(alias_enrichment_module, Mod);
|
||||
false ->
|
||||
ok
|
||||
end
|
||||
|
|
|
@ -313,7 +313,7 @@ handle_in(?CONNECT_PACKET(ConnPkt) = Packet, Channel) ->
|
|||
fun set_log_meta/2,
|
||||
fun check_banned/2,
|
||||
fun count_flapping_event/2,
|
||||
fun enrich_clientid_alias/2,
|
||||
fun enrich_with_aliases/2,
|
||||
fun auth_connect/2
|
||||
], ConnPkt, Channel#channel{conn_state = connecting}) of
|
||||
{ok, NConnPkt, NChannel = #channel{clientinfo = ClientInfo}} ->
|
||||
|
@ -1363,12 +1363,12 @@ check_banned(_ConnPkt, #channel{clientinfo = ClientInfo = #{zone := Zone}}) ->
|
|||
%%--------------------------------------------------------------------
|
||||
%% Enrich ClientID Alias
|
||||
|
||||
enrich_clientid_alias(Packet, Channel) ->
|
||||
case persistent_term:get(clientid_enrichment_module, undefined) of
|
||||
enrich_with_aliases(Packet, Channel) ->
|
||||
case persistent_term:get(alias_enrichment_module, undefined) of
|
||||
undefined ->
|
||||
{ok, Channel};
|
||||
Mod ->
|
||||
Mod:enrich_clientid_alias(Packet, Channel)
|
||||
Mod:enrich_with_aliases(Packet, Channel)
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue