Browse Source

fix: schema mod error

Zhongwen Deng 3 năm trước cách đây
mục cha
commit
7beaa91814

+ 1 - 1
apps/emqx/src/emqx_release.erl

@@ -41,7 +41,7 @@ description() ->
 
 %% @doc Return EMQX edition info.
 %% Read info from persistent_term at runtime.
-%% Or meck this function to run tests for another eidtion.
+%% Or meck this function to run tests for another edition.
 -spec edition() -> ce | ee | edge.
 -ifdef(EMQX_RELEASE_EDITION).
 edition() -> ?EMQX_RELEASE_EDITION.

+ 9 - 0
apps/emqx_conf/src/emqx_conf.erl

@@ -26,6 +26,7 @@
 -export([remove/2, remove/3]).
 -export([reset/2, reset/3]).
 -export([dump_schema/1, dump_schema/2]).
+-export([schema_module/0]).
 
 %% for rpc
 -export([get_node_and_config/1]).
@@ -145,6 +146,14 @@ dump_schema(Dir, SchemaModule) ->
     ok = gen_hot_conf_schema(HotConfigSchemaFile),
     ok.
 
+%% @doc return the root schema module.
+-spec schema_module() -> module().
+schema_module() ->
+    case os:getenv("SCHEMA_MOD") of
+        false -> emqx_conf_schema;
+        Value -> list_to_existing_atom(Value)
+    end.
+
 %%--------------------------------------------------------------------
 %% Internal functions
 %%--------------------------------------------------------------------

+ 1 - 7
apps/emqx_conf/src/emqx_conf_app.erl

@@ -35,15 +35,9 @@ stop(_State) ->
 init_conf() ->
     {ok, TnxId} = copy_override_conf_from_core_node(),
     emqx_app:set_init_tnx_id(TnxId),
-    emqx_config:init_load(schema_module()),
+    emqx_config:init_load(emqx_conf:schema_module()),
     emqx_app:set_init_config_load_done().
 
-schema_module() ->
-    case os:getenv("SCHEMA_MOD") of
-        false -> emqx_conf_schema;
-        Value -> list_to_existing_atom(Value)
-    end.
-
 copy_override_conf_from_core_node() ->
     case nodes() of
         [] -> %% The first core nodes is self.

+ 8 - 5
apps/emqx_management/src/emqx_mgmt_api_configs.erl

@@ -136,10 +136,12 @@ find_schema(Path) ->
     Configs = config_list(),
     lists:keyfind(list_to_binary(Root), 1, Configs).
 
-%% we load all configs from emqx_conf_schema, some of them are defined as local ref
-%% we need redirect to emqx_conf_schema.
-%% such as hoconsc:ref("node") to hoconsc:ref(emqx_conf_schema, "node")
-fields(Field) -> emqx_conf_schema:fields(Field).
+%% we load all configs from emqx_*_schema, some of them are defined as local ref
+%% we need redirect to emqx_*_schema.
+%% such as hoconsc:ref("node") to hoconsc:ref(emqx_*_schema, "node")
+fields(Field) ->
+    Mod = emqx_conf:schema_module(),
+    apply(Mod, fields, [Field]).
 
 %%%==============================================================================================
 %% HTTP API Callbacks
@@ -201,7 +203,8 @@ conf_path_from_querystr(Req) ->
     end.
 
 config_list() ->
-    Roots = hocon_schema:roots(emqx_conf_schema),
+    Mod = emqx_conf:schema_module(),
+    Roots = hocon_schema:roots(Mod),
     lists:foldl(fun(Key, Acc) -> lists:keydelete(Key, 1, Acc) end, Roots, ?EXCLUDES).
 
 conf_path(Req) ->

+ 1 - 1
apps/emqx_management/test/emqx_mgmt_api_configs_SUITE.erl

@@ -35,7 +35,7 @@ t_get(_Config) ->
     maps:map(fun(Name, Value) ->
         {ok, Config} = get_config(Name),
         ?assertEqual(Value, Config)
-    end, Configs),
+    end, maps:remove(<<"license">>, Configs)),
     ok.
 
 t_update(_Config) ->