Merge pull request #9637 from HJianBo/fix-clients-api

fix(clients): fix expiry_interval unit error
This commit is contained in:
JianBo He 2023-01-09 09:49:16 +08:00 committed by GitHub
commit 6f5057b9dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 14 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_management, [
{description, "EMQX Management API and CLI"},
% strict semver, bump manually!
{vsn, "5.0.10"},
{vsn, "5.0.11"},
{modules, []},
{registered, [emqx_management_sup]},
{applications, [kernel, stdlib, emqx_plugins, minirest, emqx]},

View File

@ -65,7 +65,6 @@
{<<"ip_address">>, ip},
{<<"conn_state">>, atom},
{<<"clean_start">>, atom},
{<<"proto_name">>, binary},
{<<"proto_ver">>, integer},
{<<"like_clientid">>, binary},
{<<"like_username">>, binary},
@ -145,14 +144,6 @@ schema("/clients") ->
required => false,
description => <<"Whether the client uses a new session">>
})},
{proto_name,
hoconsc:mk(hoconsc:enum(['MQTT', 'CoAP', 'LwM2M', 'MQTT-SN']), #{
in => query,
required => false,
description =>
<<"Client protocol name, ",
"the possible values are MQTT,CoAP,LwM2M,MQTT-SN">>
})},
{proto_ver,
hoconsc:mk(binary(), #{
in => query,
@ -830,8 +821,6 @@ ms(ip_address, X) ->
#{conninfo => #{peername => {X, '_'}}};
ms(clean_start, X) ->
#{conninfo => #{clean_start => X}};
ms(proto_name, X) ->
#{conninfo => #{proto_name => X}};
ms(proto_ver, X) ->
#{conninfo => #{proto_ver => X}};
ms(connected_at, X) ->
@ -879,7 +868,8 @@ format_channel_info(WhichNode, {_, ClientInfo0, ClientStats}) ->
ClientInfoMap2 = maps:put(node, Node, ClientInfoMap1),
ClientInfoMap3 = maps:put(ip_address, IpAddress, ClientInfoMap2),
ClientInfoMap4 = maps:put(port, Port, ClientInfoMap3),
ClientInfoMap = maps:put(connected, Connected, ClientInfoMap4),
ClientInfoMap5 = convert_expiry_interval_unit(ClientInfoMap4),
ClientInfoMap = maps:put(connected, Connected, ClientInfoMap5),
RemoveList =
[
@ -949,6 +939,9 @@ peername_dispart({Addr, Port}) ->
%% PortBinary = integer_to_binary(Port),
{AddrBinary, Port}.
convert_expiry_interval_unit(ClientInfoMap = #{expiry_interval := Interval}) ->
ClientInfoMap#{expiry_interval := Interval div 1000}.
format_authz_cache({{PubSub, Topic}, {AuthzResult, Timestamp}}) ->
#{
access => PubSub,

View File

@ -44,7 +44,10 @@ t_clients(_) ->
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
{ok, C1} = emqtt:start_link(#{
username => Username1, clientid => ClientId1, proto_ver => v5
username => Username1,
clientid => ClientId1,
proto_ver => v5,
properties => #{'Session-Expiry-Interval' => 120}
}),
{ok, _} = emqtt:connect(C1),
{ok, C2} = emqtt:start_link(#{username => Username2, clientid => ClientId2}),
@ -70,6 +73,7 @@ t_clients(_) ->
Client1Response = emqx_json:decode(Client1, [return_maps]),
?assertEqual(Username1, maps:get(<<"username">>, Client1Response)),
?assertEqual(ClientId1, maps:get(<<"clientid">>, Client1Response)),
?assertEqual(120, maps:get(<<"expiry_interval">>, Client1Response)),
%% delete /clients/:clientid kickout
Client2Path = emqx_mgmt_api_test_util:api_path(["clients", binary_to_list(ClientId2)]),

View File

@ -0,0 +1 @@
Fix the expiry_interval fields of the clients HTTP API to measure in seconds.

View File

@ -0,0 +1 @@
修复 clients HTTP API 下的 expiry_interval 字段的时间单位为秒。