Configure FLUs and chains with "rc.d" style configuration #56
2 changed files with 64 additions and 0 deletions
|
@ -616,3 +616,41 @@ delete_chain_config(Name, File, S) ->
|
||||||
Dst = get_chain_config_dir(S),
|
Dst = get_chain_config_dir(S),
|
||||||
ok = file:delete(Dst ++ "/" ++ atom_to_list(Name)),
|
ok = file:delete(Dst ++ "/" ++ atom_to_list(Name)),
|
||||||
S.
|
S.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
check_ast_tuple_syntax(Ts) ->
|
||||||
|
lists:partition(fun check_a_ast_tuple/1, Ts).
|
||||||
|
|
||||||
|
check_a_ast_tuple({host, Name, Props}) ->
|
||||||
|
is_stringy(Name) andalso is_proplisty(Props) andalso
|
||||||
|
lists:all(fun({admin_interface, X}) -> is_stringy(X);
|
||||||
|
({client_interface, X}) -> is_stringy(X);
|
||||||
|
(_) -> false
|
||||||
|
end, Props);
|
||||||
|
check_a_ast_tuple({flu, Name, HostName, Port, Props}) ->
|
||||||
|
is_stringy(Name) andalso is_stringy(HostName) andalso
|
||||||
|
is_porty(Port) andalso is_proplisty(Props);
|
||||||
|
check_a_ast_tuple({chain, Name, AddList, RemoveList, Props}) ->
|
||||||
|
is_stringy(Name) andalso
|
||||||
|
lists:all(fun is_stringy/1, AddList) andalso
|
||||||
|
lists:all(fun is_stringy/1, RemoveList) andalso
|
||||||
|
is_proplisty(Props);
|
||||||
|
check_a_ast_tuple(_) ->
|
||||||
|
false.
|
||||||
|
|
||||||
|
is_proplisty(Props) ->
|
||||||
|
is_list(Props) andalso
|
||||||
|
lists:all(fun({_,_}) -> true;
|
||||||
|
(X) when is_atom(X) -> true;
|
||||||
|
(_) -> false
|
||||||
|
end, Props).
|
||||||
|
|
||||||
|
is_stringy(L) ->
|
||||||
|
is_list(L) andalso
|
||||||
|
lists:all(fun(C) when 33 =< C, C =< 126 -> true;
|
||||||
|
(_) -> false
|
||||||
|
end, L).
|
||||||
|
|
||||||
|
is_porty(Port) ->
|
||||||
|
is_integer(Port) andalso 1024 =< Port andalso Port =< 65535.
|
||||||
|
|
|
@ -151,5 +151,31 @@ make_pending_config(Term) ->
|
||||||
ok = file:write_file(Dir ++ "/" ++ lists:flatten(io_lib:format("~w,~w,~w", tuple_to_list(os:timestamp()))),
|
ok = file:write_file(Dir ++ "/" ++ lists:flatten(io_lib:format("~w,~w,~w", tuple_to_list(os:timestamp()))),
|
||||||
Blob).
|
Blob).
|
||||||
|
|
||||||
|
ast_tuple_syntax_test() ->
|
||||||
|
T = fun(L) -> machi_lifecycle_mgr:check_ast_tuple_syntax(L) end,
|
||||||
|
{_Good,[]=_Bad} =
|
||||||
|
T([ {host, "localhost", []},
|
||||||
|
{host, "localhost", [{client_interface, "1.2.3.4"},
|
||||||
|
{admin_interface, "5.6.7.8"}]},
|
||||||
|
{flu, "fx", "foohost", 4000, []},
|
||||||
|
{chain, "cy", ["fx", "fy"], ["fz"], [foo,{bar,baz}]} ]),
|
||||||
|
{[],[_,_,_,_]} =
|
||||||
|
T([ {host, 'localhost', []},
|
||||||
|
{host, 'localhost', yo},
|
||||||
|
{host, "localhost", [{client_interface, 77.88293829832}]},
|
||||||
|
{host, "localhost", [{client_interface, "1.2.3.4"},
|
||||||
|
{bummer, "5.6.7.8"}]} ]),
|
||||||
|
{[],[_,_,_,_,_,_]} =
|
||||||
|
T([ {flu, 'fx', "foohost", 4000, []},
|
||||||
|
{flu, "fx", <<"foohost">>, 4000, []},
|
||||||
|
{flu, "fx", "foohost", -4000, []},
|
||||||
|
{flu, "fx", "foohost", 40009999, []},
|
||||||
|
{flu, "fx", "foohost", 4000, gack},
|
||||||
|
{flu, "fx", "foohost", 4000, [22]} ]),
|
||||||
|
{[],[_,_]} =
|
||||||
|
T([ {chain, 'cy', ["fx", "fy"], ["fz"], [foo,{bar,baz}]},
|
||||||
|
{chain, "cy", ["fx", 27], ["fz"], oops,arity,way,way,way,too,big,x}
|
||||||
|
]).
|
||||||
|
|
||||||
-endif. % !PULSE
|
-endif. % !PULSE
|
||||||
-endif. % TEST
|
-endif. % TEST
|
||||||
|
|
Loading…
Reference in a new issue