Преглед на файлове

Merge pull request #7824 from HJianBo/fix-gw-http-body

fix(gw): fix deep_merge can't update the configuration correctly
JianBo He преди 3 години
родител
ревизия
7a8a1f8b6a

+ 10 - 15
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) ->

+ 1 - 1
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]),

+ 12 - 0
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