|
|
@@ -151,8 +151,13 @@ config(get, _) ->
|
|
|
{200, emqx:get_raw_config([retainer])};
|
|
|
config(put, #{body := Body}) ->
|
|
|
try
|
|
|
- {ok, _} = emqx_retainer:update_config(Body),
|
|
|
- {200, emqx:get_raw_config([retainer])}
|
|
|
+ check_bucket_exists(
|
|
|
+ Body,
|
|
|
+ fun(Conf) ->
|
|
|
+ {ok, _} = emqx_retainer:update_config(Conf),
|
|
|
+ {200, emqx:get_raw_config([retainer])}
|
|
|
+ end
|
|
|
+ )
|
|
|
catch
|
|
|
_:Reason:_ ->
|
|
|
{400, #{
|
|
|
@@ -232,3 +237,28 @@ check_backend(Type, Params, Cont) ->
|
|
|
_ ->
|
|
|
{400, 'BAD_REQUEST', <<"This API only support built in database">>}
|
|
|
end.
|
|
|
+
|
|
|
+check_bucket_exists(
|
|
|
+ #{
|
|
|
+ <<"flow_control">> :=
|
|
|
+ #{<<"batch_deliver_limiter">> := Name} = Flow
|
|
|
+ } = Conf,
|
|
|
+ Cont
|
|
|
+) ->
|
|
|
+ case erlang:binary_to_atom(Name) of
|
|
|
+ '' ->
|
|
|
+ %% workaround, empty string means set the value to undefined,
|
|
|
+ %% but now, we can't store `undefined` in the config file correct,
|
|
|
+ %% but, we can delete this field
|
|
|
+ Cont(Conf#{
|
|
|
+ <<"flow_control">> := maps:remove(<<"batch_deliver_limiter">>, Flow)
|
|
|
+ });
|
|
|
+ Bucket ->
|
|
|
+ Path = emqx_limiter_schema:get_bucket_cfg_path(batch, Bucket),
|
|
|
+ case emqx:get_config(Path, undefined) of
|
|
|
+ undefined ->
|
|
|
+ {400, 'BAD_REQUEST', <<"The limiter bucket not exists">>};
|
|
|
+ _ ->
|
|
|
+ Cont(Conf)
|
|
|
+ end
|
|
|
+ end.
|