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

fix(gw): fix deep_merge can't update the configuration correctly
This commit is contained in:
JianBo He 2022-04-29 16:46:59 +08:00 committed by GitHub
commit 7a8a1f8b6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 16 deletions

View File

@ -493,12 +493,9 @@ pre_config_update(_, {update_authn, GwName, Conf}, RawConf) ->
of of
undefined -> undefined ->
badres_authn(not_found, GwName); badres_authn(not_found, GwName);
_ -> Authn ->
{ok, NAuthn = maps:merge(Authn, Conf),
emqx_map_lib:deep_merge( {ok, emqx_map_lib:deep_put([GwName, ?AUTHN_BIN], RawConf, NAuthn)}
RawConf,
#{GwName => #{?AUTHN_BIN => Conf}}
)}
end; end;
pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) -> pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) ->
case case
@ -517,17 +514,15 @@ pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) ->
Auth -> Auth ->
NListener = maps:put( NListener = maps:put(
?AUTHN_BIN, ?AUTHN_BIN,
emqx_map_lib:deep_merge(Auth, Conf), maps:merge(Auth, Conf),
Listener Listener
), ),
NGateway = #{ {ok,
GwName => emqx_map_lib:deep_put(
#{ [GwName, <<"listeners">>, LType, LName],
<<"listeners">> => RawConf,
#{LType => #{LName => NListener}} NListener
} )}
},
{ok, emqx_map_lib:deep_merge(RawConf, NGateway)}
end end
end; end;
pre_config_update(_, {remove_authn, GwName}, RawConf) -> pre_config_update(_, {remove_authn, GwName}, RawConf) ->

View File

@ -344,7 +344,7 @@ ensure_connected(
clientinfo = ClientInfo 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)}, NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)},
ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]), ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]),

View File

@ -262,6 +262,17 @@ enrich_clientinfo(
), ),
{ok, NPacket, Channel#channel{clientinfo = NClientInfo}}. {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) -> feedvar(Override, Packet, ConnInfo, ClientInfo) ->
Envs = #{ Envs = #{
'ConnInfo' => ConnInfo, 'ConnInfo' => ConnInfo,
@ -409,6 +420,7 @@ handle_in(Packet = ?PACKET(?CMD_CONNECT), Channel) ->
fun run_conn_hooks/2, fun run_conn_hooks/2,
fun negotiate_version/2, fun negotiate_version/2,
fun enrich_clientinfo/2, fun enrich_clientinfo/2,
fun assign_clientid_to_conninfo/2,
fun set_log_meta/2, fun set_log_meta/2,
%% TODO: How to implement the banned in the gateway instance? %% TODO: How to implement the banned in the gateway instance?
%, fun check_banned/2 %, fun check_banned/2