From d1cd5dd817ee1912e9013a82d690c3a8a33dd526 Mon Sep 17 00:00:00 2001 From: Serge Tupchii Date: Mon, 30 Oct 2023 15:57:13 +0200 Subject: [PATCH] fix(emqx_mgmt_data_backup): upgrade raw conf before validating and importing --- .../emqx_management/src/emqx_mgmt_data_backup.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_data_backup.erl b/apps/emqx_management/src/emqx_mgmt_data_backup.erl index 0717e8285..3e0b0a534 100644 --- a/apps/emqx_management/src/emqx_mgmt_data_backup.erl +++ b/apps/emqx_management/src/emqx_mgmt_data_backup.erl @@ -462,11 +462,12 @@ import_cluster_hocon(BackupDir, Opts) -> case filelib:is_regular(HoconFileName) of true -> {ok, RawConf} = hocon:files([HoconFileName]), - {ok, _} = validate_cluster_hocon(RawConf), + RawConf1 = upgrade_raw_conf(emqx_conf:schema_module(), RawConf), + {ok, _} = validate_cluster_hocon(RawConf1), maybe_print("Importing cluster configuration...~n", [], Opts), %% At this point, when all validations have been passed, we want to log errors (if any) %% but proceed with the next items, instead of aborting the whole import operation - do_import_conf(RawConf, Opts); + do_import_conf(RawConf1, Opts); false -> maybe_print("No cluster configuration to be imported.~n", [], Opts), ?SLOG(info, #{ @@ -476,6 +477,16 @@ import_cluster_hocon(BackupDir, Opts) -> #{} end. +upgrade_raw_conf(SchemaMod, RawConf) -> + _ = SchemaMod:module_info(), + case erlang:function_exported(SchemaMod, upgrade_raw_conf, 1) of + true -> + %% TODO make it a schema module behaviour in hocon_schema + apply(SchemaMod, upgrade_raw_conf, [RawConf]); + false -> + RawConf + end. + read_data_files(RawConf) -> DataDir = bin(emqx:data_dir()), {ok, Cwd} = file:get_cwd(),