fix(plugins): fix load plugin generate hocon configs fail
This commit is contained in:
parent
8978464269
commit
bc71a1e2c6
|
@ -175,7 +175,7 @@ load_ext_plugin(PluginDir) ->
|
||||||
end,
|
end,
|
||||||
ok = load_plugin_app(AppName, Ebin),
|
ok = load_plugin_app(AppName, Ebin),
|
||||||
try
|
try
|
||||||
ok = generate_configs(AppName)
|
ok = generate_configs(AppName, PluginDir)
|
||||||
catch
|
catch
|
||||||
throw : {conf_file_not_found, ConfFile} ->
|
throw : {conf_file_not_found, ConfFile} ->
|
||||||
%% this is maybe a dependency of an external plugin
|
%% this is maybe a dependency of an external plugin
|
||||||
|
@ -367,8 +367,16 @@ funlog(Key, Value) ->
|
||||||
?LOG(info, "~s = ~p", [string:join(Key, "."), Value]).
|
?LOG(info, "~s = ~p", [string:join(Key, "."), Value]).
|
||||||
|
|
||||||
generate_configs(App) ->
|
generate_configs(App) ->
|
||||||
PluginConfDir = filename:join([code:lib_dir(App), "etc"]),
|
PluginConfDir = emqx:get_env(plugins_etc_dir),
|
||||||
PluginSchemaDir = filename:join([code:lib_dir(App), "priv"]),
|
PluginSchemaDir = code:priv_dir(App),
|
||||||
|
generate_configs(App, PluginConfDir, PluginSchemaDir).
|
||||||
|
|
||||||
|
generate_configs(App, PluginDir) ->
|
||||||
|
PluginConfDir = filename:join([PluginDir, "etc"]),
|
||||||
|
PluginSchemaDir = filename:join([PluginDir, "priv"]),
|
||||||
|
generate_configs(App, PluginConfDir, PluginSchemaDir).
|
||||||
|
|
||||||
|
generate_configs(App, PluginConfDir, PluginSchemaDir) ->
|
||||||
ConfigFile = filename:join([PluginConfDir, App]) ++ ".config",
|
ConfigFile = filename:join([PluginConfDir, App]) ++ ".config",
|
||||||
case filelib:is_file(ConfigFile) of
|
case filelib:is_file(ConfigFile) of
|
||||||
true ->
|
true ->
|
||||||
|
@ -410,13 +418,14 @@ do_generate_hocon_configs(App, ConfName, SchemaFile) ->
|
||||||
SchemaMod = lists:concat([App, "_schema"]),
|
SchemaMod = lists:concat([App, "_schema"]),
|
||||||
case {filelib:is_file(ConfName), filelib:is_file(SchemaFile)} of
|
case {filelib:is_file(ConfName), filelib:is_file(SchemaFile)} of
|
||||||
{true, true} ->
|
{true, true} ->
|
||||||
{ok, RawConfig} = hocon:load(ConfName),
|
{ok, RawConfig} = hocon:load(ConfName, #{format => richmap}),
|
||||||
Config = hocon_schema:check_plain(list_to_atom(SchemaMod), RawConfig, #{atom_key => true}),
|
Config = hocon_schema:check(list_to_atom(SchemaMod), RawConfig, #{atom_key => true,
|
||||||
|
return_plain => true}),
|
||||||
emqx_config_handler:update_config(emqx_config_handler, Config);
|
emqx_config_handler:update_config(emqx_config_handler, Config);
|
||||||
{true, false} ->
|
{true, false} ->
|
||||||
error({schema_not_found, [SchemaFile]});
|
error({schema_not_found, [SchemaFile]});
|
||||||
{false, true} ->
|
{false, true} ->
|
||||||
error({config_not_found, [SchemaFile]});
|
error({config_not_found, [ConfName]});
|
||||||
{false, false} ->
|
{false, false} ->
|
||||||
error({conf_and_schema_not_found, [ConfName, SchemaFile]})
|
error({conf_and_schema_not_found, [ConfName, SchemaFile]})
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue