-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkernel_yaml.erl
82 lines (78 loc) · 3.38 KB
/
kernel_yaml.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%%%-------------------------------------------------------------------
%%% @author Evgeny Khramtsov <[email protected]>
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%%-------------------------------------------------------------------
-module(kernel_yaml).
-behaviour(conf).
%% API
-export([validator/0]).
%% Imported validators
-import(yval, [enum/1, ip/0, int/2, file/0, timeout/1, timeout/2,
bool/0, ipv4/0, atom/0, map/2, options/2, list/2,
string/0, non_empty/1, and_then/2, directory/1]).
%%%===================================================================
%%% API
%%%===================================================================
-spec validator() -> yval:validator().
validator() ->
options(
#{dist_auto_connect => enum([never, once]),
global_groups => global_groups_validator(),
inet_dist_use_interface => ip(),
inet_dist_listen_min => int(0, 65535),
inet_dist_listen_max => int(0, 65535),
inet_parse_error_log => enum([silent]),
inetrc => conf_misc:to_string(file()),
net_setuptime => conf_misc:to_seconds(timeout(second)),
net_ticktime => conf_misc:to_seconds(timeout(second)),
shutdown_timeout => timeout(millisecond, infinity),
sync_nodes_mandatory => list(atom(), [unique]),
sync_nodes_optional => list(atom(), [unique]),
sync_nodes_timeout => timeout(millisecond, infinity),
start_distribution => bool(),
start_dist_ac => bool(),
start_boot_server => bool(),
boot_server_slaves => list(ipv4(), [unique]),
start_disk_log => bool(),
start_pg2 => bool(),
start_timer => bool(),
shell_history => enum([enabled, disabled]),
shell_history_drop => list(string(), [unique]),
shell_history_file_bytes => int(51200, infinity),
shell_history_path => conf_misc:to_string(directory(write)),
shutdown_func => conf_misc:modfun_validator(1),
logger_level => enum([all, emergency, alert, critical, error,
warning, notice, info, debug, none]),
logger_sasl_compatible => bool()},
[unique]).
%%%===================================================================
%%% Internal functions
%%%===================================================================
-spec global_groups_validator() -> yval:validator().
global_groups_validator() ->
and_then(
map(atom(),
options(
#{nodes => non_empty(list(atom(), [unique])),
publish_type => enum([normal, hidden])},
[{required, [nodes]}, {return, map}])),
fun(L) ->
lists:map(
fun({Group, #{publish_type := Type, nodes := Nodes}}) ->
{Group, Type, Nodes};
({Group, #{nodes := Nodes}}) ->
{Group, Nodes}
end, L)
end).