feat(dashboard): add listener enable/disable config toggle

This commit is contained in:
Zaiming (Stone) Shi 2022-04-27 09:21:16 +02:00 committed by Zhongwen Deng
parent 2dded74584
commit 974380a3d4
3 changed files with 65 additions and 15 deletions

View File

@ -132,6 +132,16 @@ Note: `sample_interval` should be a divisor of 60."""
zh: "HTTPS" zh: "HTTPS"
} }
} }
listener_enable {
desc {
en: "Ignore or enable this listener"
zh: "忽略或启用该监听器配置"
}
label {
en: "Enable"
zh: "启用"
}
}
bind { bind {
desc { desc {
en: "Port without IP(18083) or port with specified IP(127.0.0.1:18083)." en: "Port without IP(18083) or port with specified IP(127.0.0.1:18083)."

View File

@ -153,10 +153,13 @@ apps() ->
]. ].
listeners(Listeners) -> listeners(Listeners) ->
lists:map( lists:filtermap(
fun({Protocol, Conf}) -> fun({Protocol, Conf}) ->
{Conf1, Bind} = ip_port(Conf), maps:get(enable, Conf) andalso
{listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)} begin
{Conf1, Bind} = ip_port(Conf),
{true, {listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)}}
end
end, end,
maps:to_list(Listeners) maps:to_list(Listeners)
). ).

View File

@ -76,6 +76,44 @@ fields("listeners") ->
)} )}
]; ];
fields("http") -> fields("http") ->
[
{"enable",
sc(
boolean(),
#{
default => true,
desc => ?DESC(listener_enable)
}
)}
| common_listener_fields()
];
fields("https") ->
[
{"enable",
sc(
boolean(),
#{
default => false,
desc => ?DESC(listener_enable)
}
)}
| common_listener_fields() ++
exclude_fields(
["enable", "fail_if_no_peer_cert"],
emqx_schema:server_ssl_opts_schema(#{}, true)
)
].
exclude_fields([], Fields) ->
Fields;
exclude_fields([FieldName | Rest], Fields) ->
%% assert field exists
case lists:keytake(FieldName, 1, Fields) of
{value, _, New} -> exclude_fields(Rest, New);
false -> error({FieldName, Fields})
end.
common_listener_fields() ->
[ [
{"bind", fun bind/1}, {"bind", fun bind/1},
{"num_acceptors", {"num_acceptors",
@ -126,19 +164,18 @@ fields("http") ->
desc => ?DESC(ipv6_v6only) desc => ?DESC(ipv6_v6only)
} }
)} )}
]; ].
fields("https") ->
fields("http") ++
proplists:delete(
"fail_if_no_peer_cert",
emqx_schema:server_ssl_opts_schema(#{}, true)
).
desc("dashboard") -> ?DESC(desc_dashboard); desc("dashboard") ->
desc("listeners") -> ?DESC(desc_listeners); ?DESC(desc_dashboard);
desc("http") -> ?DESC(desc_http); desc("listeners") ->
desc("https") -> ?DESC(desc_https); ?DESC(desc_listeners);
desc(_) -> undefined. desc("http") ->
?DESC(desc_http);
desc("https") ->
?DESC(desc_https);
desc(_) ->
undefined.
bind(type) -> hoconsc:union([non_neg_integer(), emqx_schema:ip_port()]); bind(type) -> hoconsc:union([non_neg_integer(), emqx_schema:ip_port()]);
bind(default) -> 18083; bind(default) -> 18083;