Merge pull request #7658 from terry-xiaoyu/dashboard_conf_no_array

refactor: change confs for dashboard listeners from array to map
This commit is contained in:
Xinyu Liu 2022-04-19 16:06:27 +08:00 committed by GitHub
commit 86e8498bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 53 deletions

View File

@ -10,34 +10,29 @@ dashboard {
sample_interval = 10s sample_interval = 10s
## JWT token expiration time. ## JWT token expiration time.
token_expired_time = 60m token_expired_time = 60m
listeners = [ listeners.http {
{ num_acceptors = 4
protocol = http max_connections = 512
num_acceptors = 4 bind = 18083
max_connections = 512 backlog = 512
bind = 18083 send_timeout = 5s
backlog = 512 inet6 = false
send_timeout = 5s ipv6_v6only = false
inet6 = false }
ipv6_v6only = false #listeners.https {
} # bind = "127.0.0.1:18084"
# , # num_acceptors = 4
# { # backlog = 512
# protocol = https # send_timeout = 5s
# bind = "127.0.0.1:18084" # inet6 = false
# num_acceptors = 2 # ipv6_v6only = false
# backlog = 512 # certfile = "etc/certs/cert.pem"
# send_timeout = 5s # keyfile = "etc/certs/key.pem"
# inet6 = false # cacertfile = "etc/certs/cacert.pem"
# ipv6_v6only = false # verify = verify_peer
# certfile = "etc/certs/cert.pem" # versions = ["tlsv1.3","tlsv1.2","tlsv1.1","tlsv1"]
# keyfile = "etc/certs/key.pem" # ciphers = ["TLS_AES_256_GCM_SHA384","TLS_AES_128_GCM_SHA256","TLS_CHACHA20_POLY1305_SHA256","TLS_AES_128_CCM_SHA256","TLS_AES_128_CCM_8_SHA256","ECDHE-ECDSA-AES256-GCM-SHA384","ECDHE-RSA-AES256-GCM-SHA384","ECDHE-ECDSA-AES256-SHA384","ECDHE-RSA-AES256-SHA384","ECDHE-ECDSA-DES-CBC3-SHA","ECDH-ECDSA-AES256-GCM-SHA384","ECDH-RSA-AES256-GCM-SHA384","ECDH-ECDSA-AES256-SHA384","ECDH-RSA-AES256-SHA384","DHE-DSS-AES256-GCM-SHA384","DHE-DSS-AES256-SHA256","AES256-GCM-SHA384","AES256-SHA256","ECDHE-ECDSA-AES128-GCM-SHA256","ECDHE-RSA-AES128-GCM-SHA256","ECDHE-ECDSA-AES128-SHA256","ECDHE-RSA-AES128-SHA256","ECDH-ECDSA-AES128-GCM-SHA256","ECDH-RSA-AES128-GCM-SHA256","ECDH-ECDSA-AES128-SHA256","ECDH-RSA-AES128-SHA256","DHE-DSS-AES128-GCM-SHA256","DHE-DSS-AES128-SHA256","AES128-GCM-SHA256","AES128-SHA256","ECDHE-ECDSA-AES256-SHA","ECDHE-RSA-AES256-SHA","DHE-DSS-AES256-SHA","ECDH-ECDSA-AES256-SHA","ECDH-RSA-AES256-SHA","AES256-SHA","ECDHE-ECDSA-AES128-SHA","ECDHE-RSA-AES128-SHA","DHE-DSS-AES128-SHA","ECDH-ECDSA-AES128-SHA","ECDH-RSA-AES128-SHA","AES128-SHA"]
# cacertfile = "etc/certs/cacert.pem" #}
# verify = verify_peer
# versions = ["tlsv1.3","tlsv1.2","tlsv1.1","tlsv1"]
# ciphers = ["TLS_AES_256_GCM_SHA384","TLS_AES_128_GCM_SHA256","TLS_CHACHA20_POLY1305_SHA256","TLS_AES_128_CCM_SHA256","TLS_AES_128_CCM_8_SHA256","ECDHE-ECDSA-AES256-GCM-SHA384","ECDHE-RSA-AES256-GCM-SHA384","ECDHE-ECDSA-AES256-SHA384","ECDHE-RSA-AES256-SHA384","ECDHE-ECDSA-DES-CBC3-SHA","ECDH-ECDSA-AES256-GCM-SHA384","ECDH-RSA-AES256-GCM-SHA384","ECDH-ECDSA-AES256-SHA384","ECDH-RSA-AES256-SHA384","DHE-DSS-AES256-GCM-SHA384","DHE-DSS-AES256-SHA256","AES256-GCM-SHA384","AES256-SHA256","ECDHE-ECDSA-AES128-GCM-SHA256","ECDHE-RSA-AES128-GCM-SHA256","ECDHE-ECDSA-AES128-SHA256","ECDHE-RSA-AES128-SHA256","ECDH-ECDSA-AES128-GCM-SHA256","ECDH-RSA-AES128-GCM-SHA256","ECDH-ECDSA-AES128-SHA256","ECDH-RSA-AES128-SHA256","DHE-DSS-AES128-GCM-SHA256","DHE-DSS-AES128-SHA256","AES128-GCM-SHA256","AES128-SHA256","ECDHE-ECDSA-AES256-SHA","ECDHE-RSA-AES256-SHA","DHE-DSS-AES256-SHA","ECDH-ECDSA-AES256-SHA","ECDH-RSA-AES256-SHA","AES256-SHA","ECDHE-ECDSA-AES128-SHA","ECDHE-RSA-AES128-SHA","DHE-DSS-AES128-SHA","ECDH-ECDSA-AES128-SHA","ECDH-RSA-AES128-SHA","AES128-SHA"]
# }
]
## CORS Support. don't set cors true if you don't know what it means. ## CORS Support. don't set cors true if you don't know what it means.
# cors = false # cors = false

View File

@ -155,16 +155,10 @@ apps() ->
]. ].
listeners(Listeners) -> listeners(Listeners) ->
[ lists:map(fun({Protocol, Conf}) ->
begin {Conf1, Bind} = ip_port(Conf),
Protocol = maps:get(protocol, ListenerOption0, http), {listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)}
{ListenerOption, Bind} = ip_port(ListenerOption0), end, maps:to_list(Listeners)).
Name = listener_name(Protocol, ListenerOption),
RanchOptions = ranch_opts(maps:without([protocol], ListenerOption)),
{Name, Protocol, Bind, RanchOptions}
end
|| ListenerOption0 <- Listeners
].
ip_port(Opts) -> ip_port(maps:take(bind, Opts), Opts). ip_port(Opts) -> ip_port(maps:take(bind, Opts), Opts).

View File

@ -31,12 +31,7 @@ fields("dashboard") ->
[ [
{listeners, {listeners,
sc( sc(
hoconsc:array( ref("listeners"),
hoconsc:union([
hoconsc:ref(?MODULE, "http"),
hoconsc:ref(?MODULE, "https")
])
),
#{ #{
desc => desc =>
"HTTP(s) listeners are identified by their protocol type and are\n" "HTTP(s) listeners are identified by their protocol type and are\n"
@ -71,17 +66,27 @@ fields("dashboard") ->
{cors, fun cors/1}, {cors, fun cors/1},
{i18n_lang, fun i18n_lang/1} {i18n_lang, fun i18n_lang/1}
]; ];
fields("http") -> fields("listeners") ->
[ [
{"protocol", {"http",
sc( sc(
hoconsc:enum([http, https]), ref("http"),
#{ #{
desc => ?DESC("protocol"), desc => "TCP listeners",
required => true, required => {false, recursively}
default => http
} }
)}, )},
{"https",
sc(
ref("https"),
#{
desc => "SSL listeners",
required => {false, recursively}
}
)}
];
fields("http") ->
[
{"bind", fun bind/1}, {"bind", fun bind/1},
{"num_acceptors", {"num_acceptors",
sc( sc(
@ -142,6 +147,8 @@ fields("https") ->
desc("dashboard") -> desc("dashboard") ->
"Configuration for EMQX dashboard."; "Configuration for EMQX dashboard.";
desc("listeners") ->
"Configuration for the dashboard listener.";
desc("http") -> desc("http") ->
"Configuration for the dashboard listener (plaintext)."; "Configuration for the dashboard listener (plaintext).";
desc("https") -> desc("https") ->
@ -201,3 +208,5 @@ i18n_lang(desc) -> "Internationalization language support.";
i18n_lang(_) -> undefined. i18n_lang(_) -> undefined.
sc(Type, Meta) -> hoconsc:mk(Type, Meta). sc(Type, Meta) -> hoconsc:mk(Type, Meta).
ref(Field) -> hoconsc:ref(?MODULE, Field).

View File

@ -75,7 +75,7 @@ end_per_suite(_Config) ->
mria:stop(). mria:stop().
set_special_configs(emqx_management) -> set_special_configs(emqx_management) ->
Listeners = [#{protocol => http, port => 8081}], Listeners = #{http => #{port => 8081}},
Config = #{listeners => Listeners, Config = #{listeners => Listeners,
applications => [#{id => "admin", secret => "public"}]}, applications => [#{id => "admin", secret => "public"}]},
emqx_config:put([emqx_management], Config), emqx_config:put([emqx_management], Config),

View File

@ -32,8 +32,11 @@ set_default_config() ->
set_default_config(<<"admin">>). set_default_config(<<"admin">>).
set_default_config(DefaultUsername) -> set_default_config(DefaultUsername) ->
Config = #{listeners => [#{protocol => http, Config = #{listeners => #{
port => 18083}], http => #{
port => 18083
}
},
default_username => DefaultUsername, default_username => DefaultUsername,
default_password => <<"public">>, default_password => <<"public">>,
i18n_lang => en i18n_lang => en