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
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) ->

View File

@ -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]),

View File

@ -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