|
|
@@ -22,7 +22,6 @@
|
|
|
-export([
|
|
|
init_load/1,
|
|
|
init_load/2,
|
|
|
- init_load/3,
|
|
|
read_override_conf/1,
|
|
|
has_deprecated_file/0,
|
|
|
delete_override_conf_files/0,
|
|
|
@@ -314,44 +313,38 @@ put_raw(KeyPath, Config) ->
|
|
|
%%============================================================================
|
|
|
init_load(SchemaMod) ->
|
|
|
ConfFiles = application:get_env(emqx, config_files, []),
|
|
|
- init_load(SchemaMod, ConfFiles, #{raw_with_default => true}).
|
|
|
-
|
|
|
-init_load(SchemaMod, Opts) when is_map(Opts) ->
|
|
|
- ConfFiles = application:get_env(emqx, config_files, []),
|
|
|
- init_load(SchemaMod, ConfFiles, Opts);
|
|
|
-init_load(SchemaMod, ConfFiles) ->
|
|
|
- init_load(SchemaMod, ConfFiles, #{raw_with_default => false}).
|
|
|
+ init_load(SchemaMod, ConfFiles).
|
|
|
|
|
|
%% @doc Initial load of the given config files.
|
|
|
%% NOTE: The order of the files is significant, configs from files ordered
|
|
|
%% in the rear of the list overrides prior values.
|
|
|
-spec init_load(module(), [string()] | binary() | hocon:config()) -> ok.
|
|
|
-init_load(SchemaMod, Conf, Opts) when is_list(Conf) orelse is_binary(Conf) ->
|
|
|
- HasDeprecatedFile = has_deprecated_file(),
|
|
|
- RawConf = load_config_files(HasDeprecatedFile, Conf),
|
|
|
- init_load(HasDeprecatedFile, SchemaMod, RawConf, Opts).
|
|
|
-
|
|
|
-init_load(true, SchemaMod, RawConf, Opts) when is_map(RawConf) ->
|
|
|
+init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) ->
|
|
|
ok = save_schema_mod_and_names(SchemaMod),
|
|
|
- %% deprecated conf will be removed in 5.1
|
|
|
- %% Merge environment variable overrides on top
|
|
|
- RawConfWithEnvs = merge_envs(SchemaMod, RawConf),
|
|
|
- Overrides = read_override_confs(),
|
|
|
- RawConfWithOverrides = hocon:deep_merge(RawConfWithEnvs, Overrides),
|
|
|
- RawConfAll = maybe_fill_defaults(SchemaMod, RawConfWithOverrides, Opts),
|
|
|
+ HasDeprecatedFile = has_deprecated_file(),
|
|
|
+ RawConf0 = load_config_files(HasDeprecatedFile, Conf),
|
|
|
+ RawConf1 =
|
|
|
+ case HasDeprecatedFile of
|
|
|
+ true ->
|
|
|
+ overlay_v0(SchemaMod, RawConf0);
|
|
|
+ false ->
|
|
|
+ overlay_v1(SchemaMod, RawConf0)
|
|
|
+ end,
|
|
|
+ RawConf = fill_defaults_for_all_roots(SchemaMod, RawConf1),
|
|
|
%% check configs against the schema
|
|
|
- {AppEnvs, CheckedConf} = check_config(SchemaMod, RawConfAll, #{}),
|
|
|
+ {AppEnvs, CheckedConf} = check_config(SchemaMod, RawConf, #{}),
|
|
|
save_to_app_env(AppEnvs),
|
|
|
- ok = save_to_config_map(CheckedConf, RawConfAll);
|
|
|
-init_load(false, SchemaMod, RawConf, Opts) when is_map(RawConf) ->
|
|
|
- ok = save_schema_mod_and_names(SchemaMod),
|
|
|
- %% Merge environment variable overrides on top
|
|
|
+ ok = save_to_config_map(CheckedConf, RawConf).
|
|
|
+
|
|
|
+%% Merge environment variable overrides on top, then merge with overrides.
|
|
|
+overlay_v0(SchemaMod, RawConf) when is_map(RawConf) ->
|
|
|
RawConfWithEnvs = merge_envs(SchemaMod, RawConf),
|
|
|
- RawConfAll = maybe_fill_defaults(SchemaMod, RawConfWithEnvs, Opts),
|
|
|
- %% check configs against the schema
|
|
|
- {AppEnvs, CheckedConf} = check_config(SchemaMod, RawConfAll, #{}),
|
|
|
- save_to_app_env(AppEnvs),
|
|
|
- ok = save_to_config_map(CheckedConf, RawConfAll).
|
|
|
+ Overrides = read_override_confs(),
|
|
|
+ hocon:deep_merge(RawConfWithEnvs, Overrides).
|
|
|
+
|
|
|
+%% Merge environment variable overrides on top.
|
|
|
+overlay_v1(SchemaMod, RawConf) when is_map(RawConf) ->
|
|
|
+ merge_envs(SchemaMod, RawConf).
|
|
|
|
|
|
%% @doc Read merged cluster + local overrides.
|
|
|
read_override_confs() ->
|
|
|
@@ -360,8 +353,7 @@ read_override_confs() ->
|
|
|
hocon:deep_merge(ClusterOverrides, LocalOverrides).
|
|
|
|
|
|
%% keep the raw and non-raw conf has the same keys to make update raw conf easier.
|
|
|
-%% TODO: remove raw_with_default as it's now always true.
|
|
|
-maybe_fill_defaults(SchemaMod, RawConf0, #{raw_with_default := true}) ->
|
|
|
+fill_defaults_for_all_roots(SchemaMod, RawConf0) ->
|
|
|
RootSchemas = hocon_schema:roots(SchemaMod),
|
|
|
%% the roots which are missing from the loaded configs
|
|
|
MissingRoots = lists:filtermap(
|
|
|
@@ -380,9 +372,7 @@ maybe_fill_defaults(SchemaMod, RawConf0, #{raw_with_default := true}) ->
|
|
|
RawConf0,
|
|
|
MissingRoots
|
|
|
),
|
|
|
- fill_defaults(RawConf);
|
|
|
-maybe_fill_defaults(_SchemaMod, RawConf, _Opts) ->
|
|
|
- RawConf.
|
|
|
+ fill_defaults(RawConf).
|
|
|
|
|
|
%% So far, this can only return true when testing.
|
|
|
%% e.g. when testing an app, we need to load its config first
|