refactor(emqx_config): check if upgrade_raw_conf is exported

This commit is contained in:
Zaiming (Stone) Shi 2023-10-25 16:14:00 +02:00
parent 6625754325
commit eed44f79a6
2 changed files with 9 additions and 6 deletions

View File

@ -325,7 +325,7 @@ init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) ->
ok = save_schema_mod_and_names(SchemaMod), ok = save_schema_mod_and_names(SchemaMod),
HasDeprecatedFile = has_deprecated_file(), HasDeprecatedFile = has_deprecated_file(),
RawConf0 = load_config_files(HasDeprecatedFile, Conf), RawConf0 = load_config_files(HasDeprecatedFile, Conf),
RawConf1 = apply(SchemaMod, upgrade_raw_conf, [RawConf0]), RawConf1 = upgrade_raw_conf(SchemaMod, RawConf0),
warning_deprecated_root_key(RawConf1), warning_deprecated_root_key(RawConf1),
RawConf2 = RawConf2 =
case HasDeprecatedFile of case HasDeprecatedFile of
@ -342,6 +342,14 @@ init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) ->
maybe_init_default_zone(), maybe_init_default_zone(),
ok. ok.
upgrade_raw_conf(SchemaMod, RawConf) ->
case erlang:function_exported(SchemaMod, upgrade_raw_conf, 1) of
true ->
SchemaMod:upgrade_raw_conf(RawConf);
false ->
RawConf
end.
%% Merge environment variable overrides on top, then merge with overrides. %% Merge environment variable overrides on top, then merge with overrides.
overlay_v0(SchemaMod, RawConf) when is_map(RawConf) -> overlay_v0(SchemaMod, RawConf) when is_map(RawConf) ->
RawConfWithEnvs = merge_envs(SchemaMod, RawConf), RawConfWithEnvs = merge_envs(SchemaMod, RawConf),

View File

@ -174,7 +174,6 @@
-export([password_converter/2, bin_str_converter/2]). -export([password_converter/2, bin_str_converter/2]).
-export([authz_fields/0]). -export([authz_fields/0]).
-export([sc/2, map/2]). -export([sc/2, map/2]).
-export([upgrade_raw_conf/1]).
-elvis([{elvis_style, god_modules, disable}]). -elvis([{elvis_style, god_modules, disable}]).
@ -183,10 +182,6 @@
-define(DEFAULT_MULTIPLIER, 1.5). -define(DEFAULT_MULTIPLIER, 1.5).
-define(DEFAULT_BACKOFF, 0.75). -define(DEFAULT_BACKOFF, 0.75).
%% dummy callback from eqmx_config:init_load
upgrade_raw_conf(RawConf) ->
RawConf.
namespace() -> broker. namespace() -> broker.
tags() -> tags() ->