fix(config): check config failed when updating
This commit is contained in:
parent
e17612b237
commit
ef59309ed0
|
@ -89,12 +89,10 @@ handle_call({add_child, ConfKeyPath, HandlerName}, _From,
|
||||||
|
|
||||||
handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
|
handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
|
||||||
#{handlers := Handlers} = State) ->
|
#{handlers := Handlers} = State) ->
|
||||||
OldConf = emqx_config:get_root(ConfKeyPath),
|
|
||||||
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
|
||||||
Reply = try
|
Reply = try
|
||||||
case process_update_request(ConfKeyPath, OldRawConf, Handlers, UpdateArgs) of
|
case process_update_request(ConfKeyPath, Handlers, UpdateArgs) of
|
||||||
{ok, NewRawConf, OverrideConf} ->
|
{ok, NewRawConf, OverrideConf} ->
|
||||||
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf, OldConf,
|
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf,
|
||||||
OverrideConf, UpdateArgs);
|
OverrideConf, UpdateArgs);
|
||||||
{error, Result} ->
|
{error, Result} ->
|
||||||
{error, Result}
|
{error, Result}
|
||||||
|
@ -121,12 +119,14 @@ terminate(_Reason, _State) ->
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
process_update_request(ConfKeyPath, OldRawConf, _Handlers, {remove, _Opts}) ->
|
process_update_request(ConfKeyPath, _Handlers, {remove, _Opts}) ->
|
||||||
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
||||||
BinKeyPath = bin_path(ConfKeyPath),
|
BinKeyPath = bin_path(ConfKeyPath),
|
||||||
NewRawConf = emqx_map_lib:deep_remove(BinKeyPath, OldRawConf),
|
NewRawConf = emqx_map_lib:deep_remove(BinKeyPath, OldRawConf),
|
||||||
OverrideConf = emqx_map_lib:deep_remove(BinKeyPath, emqx_config:read_override_conf()),
|
OverrideConf = emqx_map_lib:deep_remove(BinKeyPath, emqx_config:read_override_conf()),
|
||||||
{ok, NewRawConf, OverrideConf};
|
{ok, NewRawConf, OverrideConf};
|
||||||
process_update_request(ConfKeyPath, OldRawConf, Handlers, {{update, UpdateReq}, _Opts}) ->
|
process_update_request(ConfKeyPath, Handlers, {{update, UpdateReq}, _Opts}) ->
|
||||||
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
||||||
case do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq) of
|
case do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq) of
|
||||||
{ok, NewRawConf} ->
|
{ok, NewRawConf} ->
|
||||||
OverrideConf = update_override_config(NewRawConf),
|
OverrideConf = update_override_config(NewRawConf),
|
||||||
|
@ -146,12 +146,15 @@ do_update_config([ConfKey | ConfKeyPath], Handlers, OldRawConf, UpdateReq) ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf, OldConf, OverrideConf,
|
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf, OverrideConf,
|
||||||
UpdateArgs) ->
|
UpdateArgs) ->
|
||||||
{AppEnvs, CheckedConf} = emqx_config:check_config(SchemaModule, NewRawConf),
|
OldConf = emqx_config:get_root(ConfKeyPath),
|
||||||
case do_post_config_update(ConfKeyPath, Handlers, OldConf, CheckedConf, UpdateArgs, #{}) of
|
FullRawConf = with_full_raw_confs(NewRawConf),
|
||||||
|
{AppEnvs, CheckedConf} = emqx_config:check_config(SchemaModule, FullRawConf),
|
||||||
|
NewConf = maps:with(maps:keys(OldConf), CheckedConf),
|
||||||
|
case do_post_config_update(ConfKeyPath, Handlers, OldConf, NewConf, UpdateArgs, #{}) of
|
||||||
{ok, Result0} ->
|
{ok, Result0} ->
|
||||||
case save_configs(ConfKeyPath, AppEnvs, CheckedConf, NewRawConf, OverrideConf,
|
case save_configs(ConfKeyPath, AppEnvs, NewConf, NewRawConf, OverrideConf,
|
||||||
UpdateArgs) of
|
UpdateArgs) of
|
||||||
{ok, Result1} ->
|
{ok, Result1} ->
|
||||||
{ok, Result1#{post_config_update => Result0}};
|
{ok, Result1#{post_config_update => Result0}};
|
||||||
|
@ -231,6 +234,9 @@ return_rawconf(ConfKeyPath, #{rawconf_with_defaults := true}) ->
|
||||||
return_rawconf(ConfKeyPath, _) ->
|
return_rawconf(ConfKeyPath, _) ->
|
||||||
emqx_config:get_raw(ConfKeyPath).
|
emqx_config:get_raw(ConfKeyPath).
|
||||||
|
|
||||||
|
with_full_raw_confs(PartialConf) ->
|
||||||
|
maps:merge(emqx_config:get_raw([]), PartialConf).
|
||||||
|
|
||||||
bin_path(ConfKeyPath) -> [bin(Key) || Key <- ConfKeyPath].
|
bin_path(ConfKeyPath) -> [bin(Key) || Key <- ConfKeyPath].
|
||||||
|
|
||||||
bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
|
bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
|
||||||
|
|
|
@ -118,7 +118,7 @@ unsafe_atom_key_map(Map) ->
|
||||||
safe_atom_key_map(Map) ->
|
safe_atom_key_map(Map) ->
|
||||||
covert_keys_to_atom(Map, fun(K) -> binary_to_existing_atom(K, utf8) end).
|
covert_keys_to_atom(Map, fun(K) -> binary_to_existing_atom(K, utf8) end).
|
||||||
|
|
||||||
-spec jsonable_map(map()) -> map().
|
-spec jsonable_map(map() | list()) -> map() | list().
|
||||||
jsonable_map(Map) ->
|
jsonable_map(Map) ->
|
||||||
deep_convert(Map, fun(K, V) ->
|
deep_convert(Map, fun(K, V) ->
|
||||||
{jsonable_value(K), jsonable_value(V)}
|
{jsonable_value(K), jsonable_value(V)}
|
||||||
|
|
|
@ -120,7 +120,7 @@ config(put, Req) ->
|
||||||
Path = conf_path(Req),
|
Path = conf_path(Req),
|
||||||
{ok, #{raw_config := RawConf}} = emqx:update_config(Path, http_body(Req),
|
{ok, #{raw_config := RawConf}} = emqx:update_config(Path, http_body(Req),
|
||||||
#{rawconf_with_defaults => true}),
|
#{rawconf_with_defaults => true}),
|
||||||
{200, emqx_map_lib:deep_get(Path, emqx_map_lib:jsonable_map(RawConf))}.
|
{200, emqx_map_lib:jsonable_map(RawConf)}.
|
||||||
|
|
||||||
config_reset(post, Req) ->
|
config_reset(post, Req) ->
|
||||||
%% reset the config specified by the query string param 'conf_path'
|
%% reset the config specified by the query string param 'conf_path'
|
||||||
|
|
Loading…
Reference in New Issue