mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 17:59:31 +02:00
Add support to replace keywords in toplevel options
This commit is contained in:
parent
69b190775c
commit
896b7c7559
1 changed files with 25 additions and 8 deletions
|
@ -343,12 +343,20 @@ env_binary_to_list(Application, Parameter) ->
|
||||||
Other
|
Other
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% ejabberd_options calls this function when parsing options inside host_config
|
||||||
-spec validators([atom()]) -> {econf:validators(), [atom()]}.
|
-spec validators([atom()]) -> {econf:validators(), [atom()]}.
|
||||||
validators(Disallowed) ->
|
validators(Disallowed) ->
|
||||||
|
Host = global,
|
||||||
|
DefinedKeywords = get_defined_keywords(Host),
|
||||||
|
validators(Disallowed, DefinedKeywords).
|
||||||
|
|
||||||
|
%% validate/1 calls this function when parsing toplevel options
|
||||||
|
-spec validators([atom()], [any()]) -> {econf:validators(), [atom()]}.
|
||||||
|
validators(Disallowed, DK) ->
|
||||||
Modules = callback_modules(all),
|
Modules = callback_modules(all),
|
||||||
Validators = lists:foldl(
|
Validators = lists:foldl(
|
||||||
fun(M, Vs) ->
|
fun(M, Vs) ->
|
||||||
maps:merge(Vs, validators(M, Disallowed))
|
maps:merge(Vs, validators(M, Disallowed, DK))
|
||||||
end, #{}, Modules),
|
end, #{}, Modules),
|
||||||
Required = lists:flatmap(
|
Required = lists:flatmap(
|
||||||
fun(M) ->
|
fun(M) ->
|
||||||
|
@ -560,19 +568,27 @@ callback_modules(external) ->
|
||||||
callback_modules(all) ->
|
callback_modules(all) ->
|
||||||
callback_modules(local) ++ callback_modules(external).
|
callback_modules(local) ++ callback_modules(external).
|
||||||
|
|
||||||
-spec validators(module(), [atom()]) -> econf:validators().
|
-spec validators(module(), [atom()], [any()]) -> econf:validators().
|
||||||
validators(Mod, Disallowed) ->
|
validators(Mod, Disallowed, DK) ->
|
||||||
|
Keywords = DK ++ get_predefined_keywords(global),
|
||||||
maps:from_list(
|
maps:from_list(
|
||||||
lists:filtermap(
|
lists:filtermap(
|
||||||
fun(O) ->
|
fun(O) ->
|
||||||
case lists:member(O, Disallowed) of
|
case lists:member(O, Disallowed) of
|
||||||
true -> false;
|
true -> false;
|
||||||
false ->
|
false ->
|
||||||
{true,
|
Type =
|
||||||
try {O, Mod:opt_type(O)}
|
try Mod:opt_type(O)
|
||||||
catch _:_ ->
|
catch _:_ ->
|
||||||
{O, ejabberd_options:opt_type(O)}
|
ejabberd_options:opt_type(O)
|
||||||
end}
|
end,
|
||||||
|
TypeProcessed =
|
||||||
|
econf:and_then(
|
||||||
|
fun(B) ->
|
||||||
|
replace_keywords(global, B, Keywords)
|
||||||
|
end,
|
||||||
|
Type),
|
||||||
|
{true, {O, TypeProcessed}}
|
||||||
end
|
end
|
||||||
end, proplists:get_keys(Mod:options()))).
|
end, proplists:get_keys(Mod:options()))).
|
||||||
|
|
||||||
|
@ -665,12 +681,13 @@ validate(Y1) ->
|
||||||
{ok, Y3} ->
|
{ok, Y3} ->
|
||||||
Hosts = proplists:get_value(hosts, Y3),
|
Hosts = proplists:get_value(hosts, Y3),
|
||||||
Version = proplists:get_value(version, Y3, version()),
|
Version = proplists:get_value(version, Y3, version()),
|
||||||
|
DK = get_defined_keywords_yaml_config(Y3),
|
||||||
create_tmp_config(),
|
create_tmp_config(),
|
||||||
set_option(hosts, Hosts),
|
set_option(hosts, Hosts),
|
||||||
set_option(host, hd(Hosts)),
|
set_option(host, hd(Hosts)),
|
||||||
set_option(version, Version),
|
set_option(version, Version),
|
||||||
set_option(yaml_config, Y3),
|
set_option(yaml_config, Y3),
|
||||||
{Validators, Required} = validators([]),
|
{Validators, Required} = validators([], DK),
|
||||||
Validator = econf:options(Validators,
|
Validator = econf:options(Validators,
|
||||||
[{required, Required},
|
[{required, Required},
|
||||||
unique]),
|
unique]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue