feat: introuce attrs field in clientinfo

the 'attrs' field is to be used as extra attributes extracted
from various client properties
for example, HTTP auth result can return an extra client_attributes
field in the result which will get merged into the original
attrs field in clientinfo
This commit is contained in:
zmstone 2024-03-16 14:24:45 +01:00
parent 8e979d511c
commit f9d51484cc
3 changed files with 10 additions and 5 deletions

View File

@ -259,7 +259,8 @@ init(
mountpoint => MountPoint, mountpoint => MountPoint,
is_bridge => false, is_bridge => false,
is_superuser => false, is_superuser => false,
enable_authn => maps:get(enable_authn, Opts, true) enable_authn => maps:get(enable_authn, Opts, true),
attrs => #{}
}, },
Zone Zone
), ),

View File

@ -221,7 +221,7 @@ get_chan_info(ClientId, ChanPid) ->
wrap_rpc(emqx_cm_proto_v2:get_chan_info(ClientId, ChanPid)). wrap_rpc(emqx_cm_proto_v2:get_chan_info(ClientId, ChanPid)).
%% @doc Update infos of the channel. %% @doc Update infos of the channel.
-spec set_chan_info(emqx_types:clientid(), emqx_types:attrs()) -> boolean(). -spec set_chan_info(emqx_types:clientid(), emqx_types:channel_attrs()) -> boolean().
set_chan_info(ClientId, Info) when ?IS_CLIENTID(ClientId) -> set_chan_info(ClientId, Info) when ?IS_CLIENTID(ClientId) ->
Chan = {ClientId, self()}, Chan = {ClientId, self()},
try try

View File

@ -54,7 +54,8 @@
password/0, password/0,
peerhost/0, peerhost/0,
peername/0, peername/0,
protocol/0 protocol/0,
client_attrs/0
]). ]).
-export_type([ -export_type([
@ -106,7 +107,7 @@
-export_type([ -export_type([
caps/0, caps/0,
attrs/0, channel_attrs/0,
infos/0, infos/0,
stats/0 stats/0
]). ]).
@ -189,8 +190,11 @@
anonymous => boolean(), anonymous => boolean(),
cn => binary(), cn => binary(),
dn => binary(), dn => binary(),
%% extra attributes
attrs => client_attrs(),
atom() => term() atom() => term()
}. }.
-type client_attrs() :: #{binary() => binary()}.
-type clientid() :: binary() | atom(). -type clientid() :: binary() | atom().
-type username() :: option(binary()). -type username() :: option(binary()).
-type password() :: option(binary()). -type password() :: option(binary()).
@ -270,7 +274,7 @@
-type command() :: #command{}. -type command() :: #command{}.
-type caps() :: emqx_mqtt_caps:caps(). -type caps() :: emqx_mqtt_caps:caps().
-type attrs() :: #{atom() => term()}. -type channel_attrs() :: #{atom() => term()}.
-type infos() :: #{atom() => term()}. -type infos() :: #{atom() => term()}.
-type stats() :: [{atom(), term()}]. -type stats() :: [{atom(), term()}].