diff --git a/apps/emqx_gateway/src/emqx_gateway_conf.erl b/apps/emqx_gateway/src/emqx_gateway_conf.erl index e18e02a6f..a61754d12 100644 --- a/apps/emqx_gateway/src/emqx_gateway_conf.erl +++ b/apps/emqx_gateway/src/emqx_gateway_conf.erl @@ -493,12 +493,9 @@ pre_config_update(_, {update_authn, GwName, Conf}, RawConf) -> of undefined -> badres_authn(not_found, GwName); - _ -> - {ok, - emqx_map_lib:deep_merge( - RawConf, - #{GwName => #{?AUTHN_BIN => Conf}} - )} + Authn -> + NAuthn = maps:merge(Authn, Conf), + {ok, emqx_map_lib:deep_put([GwName, ?AUTHN_BIN], RawConf, NAuthn)} end; pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) -> case @@ -517,17 +514,15 @@ pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) -> Auth -> NListener = maps:put( ?AUTHN_BIN, - emqx_map_lib:deep_merge(Auth, Conf), + maps:merge(Auth, Conf), Listener ), - NGateway = #{ - GwName => - #{ - <<"listeners">> => - #{LType => #{LName => NListener}} - } - }, - {ok, emqx_map_lib:deep_merge(RawConf, NGateway)} + {ok, + emqx_map_lib:deep_put( + [GwName, <<"listeners">>, LType, LName], + RawConf, + NListener + )} end end; pre_config_update(_, {remove_authn, GwName}, RawConf) -> diff --git a/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_channel.erl b/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_channel.erl index 15175c39f..61b08239a 100644 --- a/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_channel.erl +++ b/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_channel.erl @@ -344,7 +344,7 @@ ensure_connected( clientinfo = ClientInfo } ) -> - _ = run_hooks(Ctx, 'client.connack', [ConnInfo, connection_accepted, []]), + _ = run_hooks(Ctx, 'client.connack', [ConnInfo, connection_accepted, #{}]), NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)}, ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]), diff --git a/apps/emqx_gateway/src/stomp/emqx_stomp_channel.erl b/apps/emqx_gateway/src/stomp/emqx_stomp_channel.erl index d137d7eab..4ef48d264 100644 --- a/apps/emqx_gateway/src/stomp/emqx_stomp_channel.erl +++ b/apps/emqx_gateway/src/stomp/emqx_stomp_channel.erl @@ -262,6 +262,17 @@ enrich_clientinfo( ), {ok, NPacket, Channel#channel{clientinfo = NClientInfo}}. +assign_clientid_to_conninfo( + Packet, + Channel = #channel{ + conninfo = ConnInfo, + clientinfo = ClientInfo + } +) -> + ClientId = maps:get(clientid, ClientInfo), + NConnInfo = maps:put(clientid, ClientId, ConnInfo), + {ok, Packet, Channel#channel{conninfo = NConnInfo}}. + feedvar(Override, Packet, ConnInfo, ClientInfo) -> Envs = #{ 'ConnInfo' => ConnInfo, @@ -409,6 +420,7 @@ handle_in(Packet = ?PACKET(?CMD_CONNECT), Channel) -> fun run_conn_hooks/2, fun negotiate_version/2, fun enrich_clientinfo/2, + fun assign_clientid_to_conninfo/2, fun set_log_meta/2, %% TODO: How to implement the banned in the gateway instance? %, fun check_banned/2