From acba1626f61d0637a2ba15dff71f4fd9fb1f7a50 Mon Sep 17 00:00:00 2001 From: firest Date: Fri, 6 May 2022 16:37:53 +0800 Subject: [PATCH] fix(mgmt): change the argument position of limiter APIs --- .../src/emqx_mgmt_api_configs.erl | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_configs.erl b/apps/emqx_management/src/emqx_mgmt_api_configs.erl index 05da32f9b..dd8e173ce 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_configs.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_configs.erl @@ -25,7 +25,6 @@ -export([ config/3, - limiter/3, config_reset/3, configs/3, get_full_config/0, @@ -169,7 +168,7 @@ schema("/configs/limiter/:limiter_type") -> hoconsc:mk( hoconsc:enum(emqx_limiter_schema:types()), #{ - in => query, + in => path, required => true, example => <<"bytes_in">>, desc => <<"The limiter type">> @@ -177,7 +176,7 @@ schema("/configs/limiter/:limiter_type") -> )} ], #{ - 'operationId' => limiter, + 'operationId' => config, get => #{ tags => [conf], description => <<"Get config of this limiter">>, @@ -243,13 +242,18 @@ fields(Field) -> %%%============================================================================================== %% HTTP API Callbacks -config(Method, Params, Req) -> +config(get, _Params, Req) -> Path = conf_path(Req), - do_config(Method, Params, Path). - -limiter(Method, #{query_string := QS} = Params, _Req) -> - #{<<"limiter_type">> := Type} = QS, - do_config(Method, Params, [<<"limiter">>, erlang:atom_to_binary(Type)]). + {ok, Conf} = emqx_map_lib:deep_find(Path, get_full_config()), + {200, Conf}; +config(put, #{body := Body}, Req) -> + Path = conf_path(Req), + case emqx_conf:update(Path, Body, ?OPTS) of + {ok, #{raw_config := RawConf}} -> + {200, RawConf}; + {error, Reason} -> + {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}} + end. global_zone_configs(get, _Params, _Req) -> Paths = global_zone_roots(), @@ -377,14 +381,3 @@ global_zone_roots() -> global_zone_schema() -> Roots = hocon_schema:roots(emqx_zone_schema), lists:map(fun({RootKey, {_Root, Schema}}) -> {RootKey, Schema} end, Roots). - -do_config(get, _Params, Path) -> - {ok, Conf} = emqx_map_lib:deep_find(Path, get_full_config()), - {200, Conf}; -do_config(put, #{body := Body}, Path) -> - case emqx_conf:update(Path, Body, ?OPTS) of - {ok, #{raw_config := RawConf}} -> - {200, RawConf}; - {error, Reason} -> - {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}} - end.