Merge pull request #9480 from olcai/fix-status-code-for-lwm2m-clients-in-api
Fix status code for lwm2m clients in api
This commit is contained in:
commit
3a31088942
|
@ -81,7 +81,7 @@ schema(?PATH("/observe")) ->
|
||||||
],
|
],
|
||||||
'requestBody' => [],
|
'requestBody' => [],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => <<"No Content">>,
|
204 => <<"No Content">>,
|
||||||
404 => error_codes(['CLIENT_NOT_FOUND'], <<"Clientid not found">>)
|
404 => error_codes(['CLIENT_NOT_FOUND'], <<"Clientid not found">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ schema(?PATH("/read")) ->
|
||||||
{path, mk(binary(), #{in => query, required => true, example => "/3/0/7"})}
|
{path, mk(binary(), #{in => query, required => true, example => "/3/0/7"})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => <<"No Content">>,
|
204 => <<"No Content">>,
|
||||||
404 => error_codes(['CLIENT_NOT_FOUND'], <<"clientid not found">>)
|
404 => error_codes(['CLIENT_NOT_FOUND'], <<"clientid not found">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ schema(?PATH("/write")) ->
|
||||||
{value, mk(binary(), #{in => query, required => true, example => 123})}
|
{value, mk(binary(), #{in => query, required => true, example => 123})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => <<"No Content">>,
|
204 => <<"No Content">>,
|
||||||
404 => error_codes(['CLIENT_NOT_FOUND'], <<"Clientid not found">>)
|
404 => error_codes(['CLIENT_NOT_FOUND'], <<"Clientid not found">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ send_cmd(ClientId, Cmd) ->
|
||||||
case emqx_gateway_cm_registry:lookup_channels(lwm2m, ClientId) of
|
case emqx_gateway_cm_registry:lookup_channels(lwm2m, ClientId) of
|
||||||
[Channel | _] ->
|
[Channel | _] ->
|
||||||
ok = emqx_lwm2m_channel:send_cmd(Channel, Cmd),
|
ok = emqx_lwm2m_channel:send_cmd(Channel, Cmd),
|
||||||
{200};
|
{204};
|
||||||
_ ->
|
_ ->
|
||||||
{404, #{code => 'CLIENT_NOT_FOUND'}}
|
{404, #{code => 'CLIENT_NOT_FOUND'}}
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -253,7 +253,7 @@ t_read(Config) ->
|
||||||
test_recv_mqtt_response(RespTopic),
|
test_recv_mqtt_response(RespTopic),
|
||||||
|
|
||||||
%% step2, call Read API
|
%% step2, call Read API
|
||||||
call_send_api(Epn, "read", "path=/3/0/0"),
|
?assertMatch({204, []}, call_send_api(Epn, "read", "path=/3/0/0")),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
||||||
?assertEqual(con, Type),
|
?assertEqual(con, Type),
|
||||||
|
@ -289,7 +289,7 @@ t_write(Config) ->
|
||||||
test_recv_mqtt_response(RespTopic),
|
test_recv_mqtt_response(RespTopic),
|
||||||
|
|
||||||
%% step2, call write API
|
%% step2, call write API
|
||||||
call_send_api(Epn, "write", "path=/3/0/13&type=Integer&value=123"),
|
?assertMatch({204, []}, call_send_api(Epn, "write", "path=/3/0/13&type=Integer&value=123")),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
||||||
?assertEqual(con, Type),
|
?assertEqual(con, Type),
|
||||||
|
@ -326,7 +326,7 @@ t_observe(Config) ->
|
||||||
test_recv_mqtt_response(RespTopic),
|
test_recv_mqtt_response(RespTopic),
|
||||||
|
|
||||||
%% step2, call observe API
|
%% step2, call observe API
|
||||||
call_deprecated_send_api(Epn, "observe", "path=/3/0/1&enable=false"),
|
?assertMatch({204, []}, call_deprecated_send_api(Epn, "observe", "path=/3/0/1&enable=false")),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
#coap_message{type = Type, method = Method, options = Opts} = test_recv_coap_request(UdpSock),
|
||||||
?assertEqual(con, Type),
|
?assertEqual(con, Type),
|
||||||
|
@ -354,9 +354,12 @@ call_deprecated_send_api(ClientId, Cmd, Query) ->
|
||||||
call_send_api(ClientId, Cmd, Query, API) ->
|
call_send_api(ClientId, Cmd, Query, API) ->
|
||||||
ApiPath = emqx_mgmt_api_test_util:api_path([API, ClientId, Cmd]),
|
ApiPath = emqx_mgmt_api_test_util:api_path([API, ClientId, Cmd]),
|
||||||
Auth = emqx_mgmt_api_test_util:auth_header_(),
|
Auth = emqx_mgmt_api_test_util:auth_header_(),
|
||||||
{ok, Response} = emqx_mgmt_api_test_util:request_api(post, ApiPath, Query, Auth),
|
Opts = #{return_all => true},
|
||||||
|
{ok, {{"HTTP/1.1", StatusCode, _}, _Headers, Response}} = emqx_mgmt_api_test_util:request_api(
|
||||||
|
post, ApiPath, Query, Auth, [], Opts
|
||||||
|
),
|
||||||
?LOGT("rest api response:~ts~n", [Response]),
|
?LOGT("rest api response:~ts~n", [Response]),
|
||||||
Response.
|
{StatusCode, Response}.
|
||||||
|
|
||||||
no_received_request(ClientId, Path, Action) ->
|
no_received_request(ClientId, Path, Action) ->
|
||||||
Response = call_lookup_api(ClientId, Path, Action),
|
Response = call_lookup_api(ClientId, Path, Action),
|
||||||
|
|
|
@ -228,10 +228,10 @@ t_configs_node({'end', _}) ->
|
||||||
t_configs_node(_) ->
|
t_configs_node(_) ->
|
||||||
Node = atom_to_list(node()),
|
Node = atom_to_list(node()),
|
||||||
|
|
||||||
?assertEqual({ok, <<"self">>}, get_configs(Node, #{return_body => true})),
|
?assertEqual({ok, <<"self">>}, get_configs(Node, #{return_all => true})),
|
||||||
?assertEqual({ok, <<"other">>}, get_configs("other_node", #{return_body => true})),
|
?assertEqual({ok, <<"other">>}, get_configs("other_node", #{return_all => true})),
|
||||||
|
|
||||||
{ExpType, ExpRes} = get_configs("unknown_node", #{return_body => true}),
|
{ExpType, ExpRes} = get_configs("unknown_node", #{return_all => true}),
|
||||||
?assertEqual(error, ExpType),
|
?assertEqual(error, ExpType),
|
||||||
?assertMatch({{_, 404, _}, _, _}, ExpRes),
|
?assertMatch({{_, 404, _}, _, _}, ExpRes),
|
||||||
{_, _, Body} = ExpRes,
|
{_, _, Body} = ExpRes,
|
||||||
|
@ -264,6 +264,7 @@ get_configs(Node, Opts) ->
|
||||||
end,
|
end,
|
||||||
URI = emqx_mgmt_api_test_util:api_path(Path),
|
URI = emqx_mgmt_api_test_util:api_path(Path),
|
||||||
case emqx_mgmt_api_test_util:request_api(get, URI, [], [], [], Opts) of
|
case emqx_mgmt_api_test_util:request_api(get, URI, [], [], [], Opts) of
|
||||||
|
{ok, {_, _, Res}} -> {ok, emqx_json:decode(Res, [return_maps])};
|
||||||
{ok, Res} -> {ok, emqx_json:decode(Res, [return_maps])};
|
{ok, Res} -> {ok, emqx_json:decode(Res, [return_maps])};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -163,7 +163,7 @@ t_publish_too_large(Config) ->
|
||||||
"",
|
"",
|
||||||
Auth,
|
Auth,
|
||||||
Body,
|
Body,
|
||||||
#{return_body => true}
|
#{return_all => true}
|
||||||
),
|
),
|
||||||
?assertMatch({_, 400, _}, Summary),
|
?assertMatch({_, 400, _}, Summary),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
@ -286,7 +286,7 @@ t_publish_bulk_dispatch_one_message_invalid_topic(Config) when is_list(Config) -
|
||||||
"",
|
"",
|
||||||
Auth,
|
Auth,
|
||||||
Body,
|
Body,
|
||||||
#{return_body => true}
|
#{return_all => true}
|
||||||
),
|
),
|
||||||
?assertMatch({_, 400, _}, Summary),
|
?assertMatch({_, 400, _}, Summary),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
@ -325,7 +325,7 @@ t_publish_bulk_dispatch_failure(Config) when is_list(Config) ->
|
||||||
"",
|
"",
|
||||||
Auth,
|
Auth,
|
||||||
Body,
|
Body,
|
||||||
#{return_body => true}
|
#{return_all => true}
|
||||||
),
|
),
|
||||||
?assertMatch({_, 503, _}, Summary),
|
?assertMatch({_, 503, _}, Summary),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
|
|
@ -89,16 +89,20 @@ request_api(Method, Url, QueryParams, AuthOrHeaders, Body, Opts) when
|
||||||
).
|
).
|
||||||
|
|
||||||
do_request_api(Method, Request, Opts) ->
|
do_request_api(Method, Request, Opts) ->
|
||||||
ReturnBody = maps:get(return_body, Opts, false),
|
ReturnAll = maps:get(return_all, Opts, false),
|
||||||
ct:pal("Method: ~p, Request: ~p", [Method, Request]),
|
ct:pal("Method: ~p, Request: ~p", [Method, Request]),
|
||||||
case httpc:request(Method, Request, [], []) of
|
case httpc:request(Method, Request, [], []) of
|
||||||
{error, socket_closed_remotely} ->
|
{error, socket_closed_remotely} ->
|
||||||
{error, socket_closed_remotely};
|
{error, socket_closed_remotely};
|
||||||
{ok, {{"HTTP/1.1", Code, _}, _, Return}} when
|
{ok, {{"HTTP/1.1", Code, _} = Reason, Headers, Body}} when
|
||||||
|
Code >= 200 andalso Code =< 299 andalso ReturnAll
|
||||||
|
->
|
||||||
|
{ok, {Reason, Headers, Body}};
|
||||||
|
{ok, {{"HTTP/1.1", Code, _}, _, Body}} when
|
||||||
Code >= 200 andalso Code =< 299
|
Code >= 200 andalso Code =< 299
|
||||||
->
|
->
|
||||||
{ok, Return};
|
{ok, Body};
|
||||||
{ok, {Reason, Headers, Body}} when ReturnBody ->
|
{ok, {Reason, Headers, Body}} when ReturnAll ->
|
||||||
{error, {Reason, Headers, Body}};
|
{error, {Reason, Headers, Body}};
|
||||||
{ok, {Reason, _Headers, _Body}} ->
|
{ok, {Reason, _Headers, _Body}} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
|
|
|
@ -34,6 +34,8 @@ Please note, the request body of `/bridges` API to configure MQTT brdige is chan
|
||||||
|
|
||||||
- Users can define the `externalTrafficPolicy` of service in EMQX Helm Chart [#9527](https://github.com/emqx/emqx/pull/9527).
|
- Users can define the `externalTrafficPolicy` of service in EMQX Helm Chart [#9527](https://github.com/emqx/emqx/pull/9527).
|
||||||
|
|
||||||
|
- Return `204` instead of `200` for `POST /gateway/lwm2m/clients/{clientid}/{read,write,observe}` [#9480](https://github.com/emqx/emqx/pull/9480).
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
- Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432).
|
- Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432).
|
||||||
|
|
|
@ -33,6 +33,8 @@ v5.0.11 或更早版本创建的配置文件,在新版本中会被自动转换
|
||||||
|
|
||||||
- 用户可以在 EMQX Helm Chart 中自定义 service 资源的 `externalTrafficPolicy` [#9527](https://github.com/emqx/emqx/pull/9527)。
|
- 用户可以在 EMQX Helm Chart 中自定义 service 资源的 `externalTrafficPolicy` [#9527](https://github.com/emqx/emqx/pull/9527)。
|
||||||
|
|
||||||
|
- 现在调用 `POST /gateway/lwm2m/clients/{clientid}/{read,write,observe}` 时,将会返回 204,而不再是 200 [#9480](https://github.com/emqx/emqx/pull/9480)。
|
||||||
|
|
||||||
## 修复
|
## 修复
|
||||||
|
|
||||||
- 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)。
|
- 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)。
|
||||||
|
|
Loading…
Reference in New Issue