From 733196aa83b2f4d43d49074ba5b086139a00a670 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 22 Dec 2023 17:56:50 +0100 Subject: [PATCH 1/2] chore: prepare for e5.4.0-build.2 --- apps/emqx/include/emqx_release.hrl | 2 +- deploy/charts/emqx-enterprise/Chart.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/emqx/include/emqx_release.hrl b/apps/emqx/include/emqx_release.hrl index 4c9fb22c6..38d26d5e4 100644 --- a/apps/emqx/include/emqx_release.hrl +++ b/apps/emqx/include/emqx_release.hrl @@ -35,7 +35,7 @@ -define(EMQX_RELEASE_CE, "5.4.0"). %% Enterprise edition --define(EMQX_RELEASE_EE, "5.4.0-build.1"). +-define(EMQX_RELEASE_EE, "5.4.0-build.2"). %% The HTTP API version -define(EMQX_API_VERSION, "5.0"). diff --git a/deploy/charts/emqx-enterprise/Chart.yaml b/deploy/charts/emqx-enterprise/Chart.yaml index 2dfb65c74..98f670cb8 100644 --- a/deploy/charts/emqx-enterprise/Chart.yaml +++ b/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 # 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 # incremented each time you make changes to the application. -appVersion: 5.4.0-build.1 +appVersion: 5.4.0-build.2 From ac6e4cf2ccc086115933e60a88995b8868ad4408 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 22 Dec 2023 17:21:08 +0100 Subject: [PATCH 2/2] fix: config update for ft --- apps/emqx/src/emqx.app.src | 2 +- apps/emqx_ft/test/emqx_ft_api_SUITE.erl | 35 +++++++++++++------ .../src/emqx_management.app.src | 2 +- .../src/emqx_mgmt_api_configs.erl | 31 ++++++++++++---- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/apps/emqx/src/emqx.app.src b/apps/emqx/src/emqx.app.src index 104f18482..f837161be 100644 --- a/apps/emqx/src/emqx.app.src +++ b/apps/emqx/src/emqx.app.src @@ -2,7 +2,7 @@ {application, emqx, [ {id, "emqx"}, {description, "EMQX Core"}, - {vsn, "5.1.16"}, + {vsn, "5.1.17"}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqx_ft/test/emqx_ft_api_SUITE.erl b/apps/emqx_ft/test/emqx_ft_api_SUITE.erl index 727e311bd..66f770a22 100644 --- a/apps/emqx_ft/test/emqx_ft_api_SUITE.erl +++ b/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( {ok, 200, #{<<"enable">> := true, <<"storage">> := #{}}}, - request_json(get, uri(["file_transfer"]), Config) + request_json(get, Uri, Config) ), ?assertMatch( {ok, 200, #{<<"enable">> := false}}, - request_json(put, uri(["file_transfer"]), #{<<"enable">> => false}, Config) + request_json(put, Uri, #{<<"enable">> => false}, Config) ), ?assertMatch( {ok, 200, #{<<"enable">> := false}}, - request_json(get, uri(["file_transfer"]), Config) + request_json(get, Uri, Config) ), ?assertMatch( {ok, 200, #{}}, request_json( put, - uri(["file_transfer"]), + Uri, #{ <<"enable">> => true, <<"storage">> => emqx_ft_test_helpers:local_storage(Config) @@ -306,7 +314,7 @@ t_configure(Config) -> {ok, 400, _}, request( put, - uri(["file_transfer"]), + Uri, #{ <<"enable">> => true, <<"storage">> => #{ @@ -321,7 +329,7 @@ t_configure(Config) -> {ok, 400, _}, request( put, - uri(["file_transfer"]), + Uri, #{ <<"enable">> => true, <<"storage">> => #{ @@ -349,7 +357,7 @@ t_configure(Config) -> {ok, 200, GetConfigJson} = request_json( put, - uri(["file_transfer"]), + Uri, #{ <<"enable">> => true, <<"storage">> => #{ @@ -388,7 +396,7 @@ t_configure(Config) -> {ok, 400, _}, request_json( put, - uri(["file_transfer"]), + Uri, #{ <<"enable">> => true, <<"storage">> => #{ @@ -410,7 +418,7 @@ t_configure(Config) -> {ok, 200, #{}}, request_json( put, - uri(["file_transfer"]), + Uri, emqx_utils_maps:deep_merge( GetConfigJson, #{ @@ -492,7 +500,12 @@ request_json(Method, Url, Config) -> request_json(Method, Url, [], Config). 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) -> KVs = lists:map(fun({K, V}) -> uri_encode(K) ++ "=" ++ uri_encode(V) end, maps:to_list(Params)), diff --git a/apps/emqx_management/src/emqx_management.app.src b/apps/emqx_management/src/emqx_management.app.src index 1ace013a2..c97577c58 100644 --- a/apps/emqx_management/src/emqx_management.app.src +++ b/apps/emqx_management/src/emqx_management.app.src @@ -2,7 +2,7 @@ {application, emqx_management, [ {description, "EMQX Management API and CLI"}, % strict semver, bump manually! - {vsn, "5.0.35"}, + {vsn, "5.0.36"}, {modules, []}, {registered, [emqx_management_sup]}, {applications, [ diff --git a/apps/emqx_management/src/emqx_mgmt_api_configs.erl b/apps/emqx_management/src/emqx_mgmt_api_configs.erl index 22fcdd907..ca5a95966 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_configs.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_configs.erl @@ -34,7 +34,7 @@ -define(PREFIX, "/configs/"). -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(TAGS, ["Configs"]). @@ -267,7 +267,7 @@ schema(Path) -> 'requestBody' => Schema, responses => #{ 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']) } } @@ -287,11 +287,17 @@ fields(Field) -> %%%============================================================================================== %% 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), + 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 {ok, #{raw_config := RawConf}} -> {200, RawConf}; @@ -299,6 +305,19 @@ config(put, #{body := NewConf}, Req) -> {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}} 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) -> {200, get_zones()}; global_zone_configs(put, #{body := Body}, _Req) ->