Просмотр исходного кода

Merge pull request #12225 from zmstone/1222-fix-config-update-for-ft

1222 fix config update for ft
Zaiming (Stone) Shi 2 лет назад
Родитель
Сommit
77c0a288b2

+ 1 - 1
apps/emqx/include/emqx_release.hrl

@@ -35,7 +35,7 @@
 -define(EMQX_RELEASE_CE, "5.4.0").
 -define(EMQX_RELEASE_CE, "5.4.0").
 
 
 %% Enterprise edition
 %% Enterprise edition
--define(EMQX_RELEASE_EE, "5.4.0-build.1").
+-define(EMQX_RELEASE_EE, "5.4.0-build.2").
 
 
 %% The HTTP API version
 %% The HTTP API version
 -define(EMQX_API_VERSION, "5.0").
 -define(EMQX_API_VERSION, "5.0").

+ 1 - 1
apps/emqx/src/emqx.app.src

@@ -2,7 +2,7 @@
 {application, emqx, [
 {application, emqx, [
     {id, "emqx"},
     {id, "emqx"},
     {description, "EMQX Core"},
     {description, "EMQX Core"},
-    {vsn, "5.1.16"},
+    {vsn, "5.1.17"},
     {modules, []},
     {modules, []},
     {registered, []},
     {registered, []},
     {applications, [
     {applications, [

+ 24 - 11
apps/emqx_ft/test/emqx_ft_api_SUITE.erl

@@ -277,24 +277,32 @@ t_ft_disabled(Config) ->
         )
         )
     ).
     ).
 
 
-t_configure(Config) ->
+t_configure_1(Config) ->
+    Uri = uri(["file_transfer"]),
+    test_configure(Uri, Config).
+
+t_configure_2(Config) ->
+    Uri = uri(["configs/file_transfer"]),
+    test_configure(Uri, Config).
+
+test_configure(Uri, Config) ->
     ?assertMatch(
     ?assertMatch(
         {ok, 200, #{<<"enable">> := true, <<"storage">> := #{}}},
         {ok, 200, #{<<"enable">> := true, <<"storage">> := #{}}},
-        request_json(get, uri(["file_transfer"]), Config)
+        request_json(get, Uri, Config)
     ),
     ),
     ?assertMatch(
     ?assertMatch(
         {ok, 200, #{<<"enable">> := false}},
         {ok, 200, #{<<"enable">> := false}},
-        request_json(put, uri(["file_transfer"]), #{<<"enable">> => false}, Config)
+        request_json(put, Uri, #{<<"enable">> => false}, Config)
     ),
     ),
     ?assertMatch(
     ?assertMatch(
         {ok, 200, #{<<"enable">> := false}},
         {ok, 200, #{<<"enable">> := false}},
-        request_json(get, uri(["file_transfer"]), Config)
+        request_json(get, Uri, Config)
     ),
     ),
     ?assertMatch(
     ?assertMatch(
         {ok, 200, #{}},
         {ok, 200, #{}},
         request_json(
         request_json(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             #{
             #{
                 <<"enable">> => true,
                 <<"enable">> => true,
                 <<"storage">> => emqx_ft_test_helpers:local_storage(Config)
                 <<"storage">> => emqx_ft_test_helpers:local_storage(Config)
@@ -306,7 +314,7 @@ t_configure(Config) ->
         {ok, 400, _},
         {ok, 400, _},
         request(
         request(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             #{
             #{
                 <<"enable">> => true,
                 <<"enable">> => true,
                 <<"storage">> => #{
                 <<"storage">> => #{
@@ -321,7 +329,7 @@ t_configure(Config) ->
         {ok, 400, _},
         {ok, 400, _},
         request(
         request(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             #{
             #{
                 <<"enable">> => true,
                 <<"enable">> => true,
                 <<"storage">> => #{
                 <<"storage">> => #{
@@ -349,7 +357,7 @@ t_configure(Config) ->
     {ok, 200, GetConfigJson} =
     {ok, 200, GetConfigJson} =
         request_json(
         request_json(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             #{
             #{
                 <<"enable">> => true,
                 <<"enable">> => true,
                 <<"storage">> => #{
                 <<"storage">> => #{
@@ -388,7 +396,7 @@ t_configure(Config) ->
         {ok, 400, _},
         {ok, 400, _},
         request_json(
         request_json(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             #{
             #{
                 <<"enable">> => true,
                 <<"enable">> => true,
                 <<"storage">> => #{
                 <<"storage">> => #{
@@ -410,7 +418,7 @@ t_configure(Config) ->
         {ok, 200, #{}},
         {ok, 200, #{}},
         request_json(
         request_json(
             put,
             put,
-            uri(["file_transfer"]),
+            Uri,
             emqx_utils_maps:deep_merge(
             emqx_utils_maps:deep_merge(
                 GetConfigJson,
                 GetConfigJson,
                 #{
                 #{
@@ -492,7 +500,12 @@ request_json(Method, Url, Config) ->
     request_json(Method, Url, [], Config).
     request_json(Method, Url, [], Config).
 
 
 json(Body) when is_binary(Body) ->
 json(Body) when is_binary(Body) ->
-    emqx_utils_json:decode(Body, [return_maps]).
+    try
+        emqx_utils_json:decode(Body, [return_maps])
+    catch
+        _:_ ->
+            error({bad_json, Body})
+    end.
 
 
 query(Params) ->
 query(Params) ->
     KVs = lists:map(fun({K, V}) -> uri_encode(K) ++ "=" ++ uri_encode(V) end, maps:to_list(Params)),
     KVs = lists:map(fun({K, V}) -> uri_encode(K) ++ "=" ++ uri_encode(V) end, maps:to_list(Params)),

+ 1 - 1
apps/emqx_management/src/emqx_management.app.src

@@ -2,7 +2,7 @@
 {application, emqx_management, [
 {application, emqx_management, [
     {description, "EMQX Management API and CLI"},
     {description, "EMQX Management API and CLI"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "5.0.35"},
+    {vsn, "5.0.36"},
     {modules, []},
     {modules, []},
     {registered, [emqx_management_sup]},
     {registered, [emqx_management_sup]},
     {applications, [
     {applications, [

+ 25 - 6
apps/emqx_management/src/emqx_mgmt_api_configs.erl

@@ -34,7 +34,7 @@
 
 
 -define(PREFIX, "/configs/").
 -define(PREFIX, "/configs/").
 -define(PREFIX_RESET, "/configs_reset/").
 -define(PREFIX_RESET, "/configs_reset/").
--define(ERR_MSG(MSG), list_to_binary(io_lib:format("~p", [MSG]))).
+-define(ERR_MSG(MSG), list_to_binary(io_lib:format("~0p", [MSG]))).
 -define(OPTS, #{rawconf_with_defaults => true, override_to => cluster}).
 -define(OPTS, #{rawconf_with_defaults => true, override_to => cluster}).
 -define(TAGS, ["Configs"]).
 -define(TAGS, ["Configs"]).
 
 
@@ -267,7 +267,7 @@ schema(Path) ->
             'requestBody' => Schema,
             'requestBody' => Schema,
             responses => #{
             responses => #{
                 200 => Schema,
                 200 => Schema,
-                400 => emqx_dashboard_swagger:error_codes(['UPDATE_FAILED']),
+                400 => emqx_dashboard_swagger:error_codes(['UPDATE_FAILED', 'INVALID_CONFIG']),
                 403 => emqx_dashboard_swagger:error_codes(['UPDATE_FAILED'])
                 403 => emqx_dashboard_swagger:error_codes(['UPDATE_FAILED'])
             }
             }
         }
         }
@@ -287,11 +287,17 @@ fields(Field) ->
 
 
 %%%==============================================================================================
 %%%==============================================================================================
 %% HTTP API Callbacks
 %% HTTP API Callbacks
-config(get, _Params, Req) ->
-    [Path] = conf_path(Req),
-    {200, get_raw_config(Path)};
-config(put, #{body := NewConf}, Req) ->
+config(Method, Data, Req) ->
     Path = conf_path(Req),
     Path = conf_path(Req),
+    do_config(Path, Method, Data).
+
+do_config([<<"file_transfer">> | Path], Method, Data) ->
+    [] =/= Path andalso throw("file_transfer does no support deep config get/put"),
+    forward_file_transfer(Method, Data);
+do_config([ConfigRoot | Path], get, _Params) ->
+    [] =/= Path andalso throw("deep config get is not supported"),
+    {200, get_raw_config(ConfigRoot)};
+do_config(Path, put, #{body := NewConf}) ->
     case emqx_conf:update(Path, NewConf, ?OPTS) of
     case emqx_conf:update(Path, NewConf, ?OPTS) of
         {ok, #{raw_config := RawConf}} ->
         {ok, #{raw_config := RawConf}} ->
             {200, RawConf};
             {200, RawConf};
@@ -299,6 +305,19 @@ config(put, #{body := NewConf}, Req) ->
             {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}}
             {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}}
     end.
     end.
 
 
+%% @private file_transfer config update reside in this module
+%% because it's needed to generate hotconf schema for dashboard UI rendering.
+%% As a result of adding "file_transfer" root key to the root keys list
+%% there is also a configs/file_transfer http path handler to be implemented.
+%% Here we simply forward the call to the file_transfer API module.
+-if(?EMQX_RELEASE_EDITION == ee).
+forward_file_transfer(Method, Data) ->
+    emqx_ft_api:'/file_transfer'(Method, Data).
+-else.
+forward_file_transfer(_Method, _Data) ->
+    {400, #{code => 'BAD_REQUEST', message => <<"not supported">>}}.
+-endif.
+
 global_zone_configs(get, _Params, _Req) ->
 global_zone_configs(get, _Params, _Req) ->
     {200, get_zones()};
     {200, get_zones()};
 global_zone_configs(put, #{body := Body}, _Req) ->
 global_zone_configs(put, #{body := Body}, _Req) ->

+ 2 - 2
deploy/charts/emqx-enterprise/Chart.yaml

@@ -14,8 +14,8 @@ type: application
 
 
 # This is the chart version. This version number should be incremented each time you make changes
 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
 # to the chart and its templates, including the app version.
-version: 5.4.0-build.1
+version: 5.4.0-build.2
 
 
 # This is the version number of the application being deployed. This version number should be
 # This is the version number of the application being deployed. This version number should be
 # incremented each time you make changes to the application.
 # incremented each time you make changes to the application.
-appVersion: 5.4.0-build.1
+appVersion: 5.4.0-build.2