fix(mgmt): change the argument position of limiter APIs

This commit is contained in:
firest 2022-05-06 16:37:53 +08:00
parent 90493e72a9
commit acba1626f6
1 changed files with 13 additions and 20 deletions

View File

@ -25,7 +25,6 @@
-export([ -export([
config/3, config/3,
limiter/3,
config_reset/3, config_reset/3,
configs/3, configs/3,
get_full_config/0, get_full_config/0,
@ -169,7 +168,7 @@ schema("/configs/limiter/:limiter_type") ->
hoconsc:mk( hoconsc:mk(
hoconsc:enum(emqx_limiter_schema:types()), hoconsc:enum(emqx_limiter_schema:types()),
#{ #{
in => query, in => path,
required => true, required => true,
example => <<"bytes_in">>, example => <<"bytes_in">>,
desc => <<"The limiter type">> desc => <<"The limiter type">>
@ -177,7 +176,7 @@ schema("/configs/limiter/:limiter_type") ->
)} )}
], ],
#{ #{
'operationId' => limiter, 'operationId' => config,
get => #{ get => #{
tags => [conf], tags => [conf],
description => <<"Get config of this limiter">>, description => <<"Get config of this limiter">>,
@ -243,13 +242,18 @@ fields(Field) ->
%%%============================================================================================== %%%==============================================================================================
%% HTTP API Callbacks %% HTTP API Callbacks
config(Method, Params, Req) -> config(get, _Params, Req) ->
Path = conf_path(Req), Path = conf_path(Req),
do_config(Method, Params, Path). {ok, Conf} = emqx_map_lib:deep_find(Path, get_full_config()),
{200, Conf};
limiter(Method, #{query_string := QS} = Params, _Req) -> config(put, #{body := Body}, Req) ->
#{<<"limiter_type">> := Type} = QS, Path = conf_path(Req),
do_config(Method, Params, [<<"limiter">>, erlang:atom_to_binary(Type)]). 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) -> global_zone_configs(get, _Params, _Req) ->
Paths = global_zone_roots(), Paths = global_zone_roots(),
@ -377,14 +381,3 @@ global_zone_roots() ->
global_zone_schema() -> global_zone_schema() ->
Roots = hocon_schema:roots(emqx_zone_schema), Roots = hocon_schema:roots(emqx_zone_schema),
lists:map(fun({RootKey, {_Root, Schema}}) -> {RootKey, Schema} end, Roots). 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.