fix(config): emqx_config:fill_defaults/1,2 not working
This commit is contained in:
parent
ef1b617624
commit
12b8297745
|
@ -261,7 +261,7 @@ init_load(SchemaMod, RawRichConf) when is_map(RawRichConf) ->
|
||||||
normalize_conf(hocon_schema:richmap_to_map(RawRichConf))).
|
normalize_conf(hocon_schema:richmap_to_map(RawRichConf))).
|
||||||
|
|
||||||
normalize_conf(Conf) ->
|
normalize_conf(Conf) ->
|
||||||
maps:with(get_root_names(bin), Conf).
|
maps:with(get_root_names(), Conf).
|
||||||
|
|
||||||
-spec check_config(module(), raw_config()) -> {AppEnvs, CheckedConf}
|
-spec check_config(module(), raw_config()) -> {AppEnvs, CheckedConf}
|
||||||
when AppEnvs :: app_envs(), CheckedConf :: config().
|
when AppEnvs :: app_envs(), CheckedConf :: config().
|
||||||
|
@ -277,7 +277,7 @@ check_config(SchemaMod, RawConf) ->
|
||||||
|
|
||||||
-spec fill_defaults(raw_config()) -> map().
|
-spec fill_defaults(raw_config()) -> map().
|
||||||
fill_defaults(RawConf) ->
|
fill_defaults(RawConf) ->
|
||||||
RootNames = get_root_names(bin),
|
RootNames = get_root_names(),
|
||||||
maps:fold(fun(Key, Conf, Acc) ->
|
maps:fold(fun(Key, Conf, Acc) ->
|
||||||
SubMap = #{Key => Conf},
|
SubMap = #{Key => Conf},
|
||||||
WithDefaults = case lists:member(Key, RootNames) of
|
WithDefaults = case lists:member(Key, RootNames) of
|
||||||
|
@ -320,9 +320,6 @@ get_schema_mod(RootName) ->
|
||||||
get_root_names() ->
|
get_root_names() ->
|
||||||
maps:get(names, persistent_term:get(?PERSIS_SCHEMA_MODS, #{names => []})).
|
maps:get(names, persistent_term:get(?PERSIS_SCHEMA_MODS, #{names => []})).
|
||||||
|
|
||||||
get_root_names(bin) ->
|
|
||||||
maps:keys(get_schema_mod()).
|
|
||||||
|
|
||||||
-spec save_configs(app_envs(), config(), raw_config(), raw_config()) -> ok | {error, term()}.
|
-spec save_configs(app_envs(), config(), raw_config(), raw_config()) -> ok | {error, term()}.
|
||||||
save_configs(_AppEnvs, Conf, RawConf, OverrideConf) ->
|
save_configs(_AppEnvs, Conf, RawConf, OverrideConf) ->
|
||||||
%% We may need also support hot config update for the apps that use application envs.
|
%% We may need also support hot config update for the apps that use application envs.
|
||||||
|
@ -412,14 +409,7 @@ do_deep_put(?RAW_CONF, KeyPath, Map, Value) ->
|
||||||
|
|
||||||
root_names_from_conf(RawConf) ->
|
root_names_from_conf(RawConf) ->
|
||||||
Keys = maps:keys(RawConf),
|
Keys = maps:keys(RawConf),
|
||||||
StrNames = [str(K) || K <- Keys],
|
[Name || Name <- get_root_names(), lists:member(Name, Keys)].
|
||||||
AtomNames = lists:foldl(fun(K, Acc) ->
|
|
||||||
try [atom(K) | Acc]
|
|
||||||
catch error:badarg -> Acc
|
|
||||||
end
|
|
||||||
end, [], Keys),
|
|
||||||
PossibleNames = StrNames ++ AtomNames,
|
|
||||||
[Name || Name <- get_root_names(), lists:member(Name, PossibleNames)].
|
|
||||||
|
|
||||||
atom(Bin) when is_binary(Bin) ->
|
atom(Bin) when is_binary(Bin) ->
|
||||||
binary_to_existing_atom(Bin, latin1);
|
binary_to_existing_atom(Bin, latin1);
|
||||||
|
@ -428,13 +418,6 @@ atom(Str) when is_list(Str) ->
|
||||||
atom(Atom) when is_atom(Atom) ->
|
atom(Atom) when is_atom(Atom) ->
|
||||||
Atom.
|
Atom.
|
||||||
|
|
||||||
str(Bin) when is_binary(Bin) ->
|
|
||||||
binary_to_list(Bin);
|
|
||||||
str(Str) when is_list(Str) ->
|
|
||||||
Str;
|
|
||||||
str(Atom) when is_atom(Atom) ->
|
|
||||||
atom_to_list(Atom).
|
|
||||||
|
|
||||||
bin(Bin) when is_binary(Bin) -> Bin;
|
bin(Bin) when is_binary(Bin) -> Bin;
|
||||||
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
||||||
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(emqx_config_SUITE).
|
||||||
|
|
||||||
|
-compile(export_all).
|
||||||
|
-compile(nowarn_export_all).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
|
init_per_suite(Config) ->
|
||||||
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
emqx_ct_helpers:start_apps([]),
|
||||||
|
Config.
|
||||||
|
|
||||||
|
end_per_suite(_Config) ->
|
||||||
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
|
t_fill_default_values(_) ->
|
||||||
|
Conf = #{
|
||||||
|
<<"broker">> => #{
|
||||||
|
<<"perf">> => #{},
|
||||||
|
<<"route_batch_clean">> => false}
|
||||||
|
},
|
||||||
|
?assertMatch(#{<<"broker">> :=
|
||||||
|
#{<<"enable_session_registry">> := true,
|
||||||
|
<<"perf">> :=
|
||||||
|
#{<<"route_lock_type">> := key,
|
||||||
|
<<"trie_compaction">> := true},
|
||||||
|
<<"route_batch_clean">> := false,
|
||||||
|
<<"session_locking_strategy">> := quorum,
|
||||||
|
<<"shared_dispatch_ack_enabled">> := false,
|
||||||
|
<<"shared_subscription_strategy">> := round_robin,
|
||||||
|
<<"sys_heartbeat_interval">> := "30s",
|
||||||
|
<<"sys_msg_interval">> := "1m"}},
|
||||||
|
emqx_config:fill_defaults(Conf)).
|
Loading…
Reference in New Issue