Просмотр исходного кода

feat: rename gateway's tcp/ssl/udp/dtls to *_options

Zhongwen Deng 3 лет назад
Родитель
Сommit
02872fb8c2

+ 7 - 7
apps/emqx_gateway/src/emqx_gateway_api_listeners.erl

@@ -635,7 +635,7 @@ examples_listener() ->
                         acceptors => 16,
                         max_connections => 1024000,
                         max_conn_rate => 1000,
-                        tcp =>
+                        tcp_options =>
                             #{
                                 active_n => 100,
                                 backlog => 1024,
@@ -662,7 +662,7 @@ examples_listener() ->
                         max_connections => 1024000,
                         max_conn_rate => 1000,
                         access_rules => [<<"allow all">>],
-                        ssl =>
+                        ssl_options =>
                             #{
                                 versions => [
                                     <<"tlsv1.3">>,
@@ -676,7 +676,7 @@ examples_listener() ->
                                 verify => <<"verify_none">>,
                                 fail_if_no_peer_cert => false
                             },
-                        tcp =>
+                        tcp_options =>
                             #{
                                 active_n => 100,
                                 backlog => 1024
@@ -691,7 +691,7 @@ examples_listener() ->
                         name => <<"udp-def">>,
                         type => udp,
                         bind => <<"22212">>,
-                        udp =>
+                        udp_options =>
                             #{
                                 active_n => 100,
                                 recbuf => <<"10KB">>,
@@ -713,7 +713,7 @@ examples_listener() ->
                         max_connections => 1024000,
                         max_conn_rate => 1000,
                         access_rules => [<<"allow all">>],
-                        dtls =>
+                        dtls_options =>
                             #{
                                 versions => [<<"dtlsv1.2">>, <<"dtlsv1">>],
                                 cacertfile => emqx:cert_file(<<"cacert.pem">>),
@@ -722,7 +722,7 @@ examples_listener() ->
                                 verify => <<"verify_none">>,
                                 fail_if_no_peer_cert => false
                             },
-                        udp =>
+                        udp_options =>
                             #{
                                 active_n => 100,
                                 backlog => 1024
@@ -740,7 +740,7 @@ examples_listener() ->
                         acceptors => 16,
                         max_connections => 1024000,
                         max_conn_rate => 1000,
-                        dtls =>
+                        dtls_options =>
                             #{
                                 versions => [<<"dtlsv1.2">>, <<"dtlsv1">>],
                                 cacertfile => emqx:cert_file(<<"cacert.pem">>),

+ 7 - 5
apps/emqx_gateway/src/emqx_gateway_conf.erl

@@ -73,7 +73,7 @@
 -type map_or_err() :: {ok, map()} | {error, term()}.
 -type listener_ref() :: {ListenerType :: atom_or_bin(), ListenerName :: atom_or_bin()}.
 
--define(IS_SSL(T), (T == <<"ssl">> orelse T == <<"dtls">>)).
+-define(IS_SSL(T), (T == <<"ssl_options">> orelse T == <<"dtls_options">>)).
 
 %%--------------------------------------------------------------------
 %%  Load/Unload
@@ -693,7 +693,7 @@ certs_dir(GwName) when is_binary(GwName) ->
     GwName.
 
 convert_certs(SubDir, Conf) ->
-    convert_certs(<<"dtls">>, SubDir, convert_certs(<<"ssl">>, SubDir, Conf)).
+    convert_certs(<<"dtls_options">>, SubDir, convert_certs(<<"ssl_options">>, SubDir, Conf)).
 
 convert_certs(Type, SubDir, Conf) when ?IS_SSL(Type) ->
     case
@@ -709,7 +709,9 @@ convert_certs(Type, SubDir, Conf) when ?IS_SSL(Type) ->
             throw({bad_ssl_config, Reason})
     end;
 convert_certs(SubDir, NConf, OConf) when is_map(NConf); is_map(OConf) ->
-    convert_certs(<<"dtls">>, SubDir, convert_certs(<<"ssl">>, SubDir, NConf, OConf), OConf).
+    convert_certs(
+        <<"dtls_options">>, SubDir, convert_certs(<<"ssl_options">>, SubDir, NConf, OConf), OConf
+    ).
 
 convert_certs(Type, SubDir, NConf, OConf) when ?IS_SSL(Type) ->
     OSSL = maps:get(Type, OConf, undefined),
@@ -727,8 +729,8 @@ new_ssl_config(_Type, Conf, undefined) -> Conf;
 new_ssl_config(Type, Conf, SSL) when ?IS_SSL(Type) -> Conf#{Type => SSL}.
 
 clear_certs(SubDir, Conf) ->
-    clear_certs(<<"ssl">>, SubDir, Conf),
-    clear_certs(<<"dtls">>, SubDir, Conf).
+    clear_certs(<<"ssl_options">>, SubDir, Conf),
+    clear_certs(<<"dtls_options">>, SubDir, Conf).
 
 clear_certs(Type, SubDir, Conf) when ?IS_SSL(Type) ->
     SSL = maps:get(Type, Conf, undefined),

+ 6 - 6
apps/emqx_gateway/src/emqx_gateway_schema.erl

@@ -339,7 +339,7 @@ fields(exproto_grpc_server) ->
                     desc => ?DESC(exproto_grpc_server_bind)
                 }
             )},
-        {ssl,
+        {ssl_options,
             sc(
                 ref(ssl_server_opts),
                 #{
@@ -351,7 +351,7 @@ fields(exproto_grpc_server) ->
 fields(exproto_grpc_handler) ->
     [
         {address, sc(binary(), #{required => true, desc => ?DESC(exproto_grpc_handler_address)})},
-        {ssl,
+        {ssl_options,
             sc(
                 ref(emqx_schema, "ssl_client_opts"),
                 #{
@@ -466,7 +466,7 @@ fields(tcp_listener) ->
 fields(ssl_listener) ->
     fields(tcp_listener) ++
         [
-            {ssl,
+            {ssl_options,
                 sc(
                     hoconsc:ref(emqx_schema, "listener_ssl_opts"),
                     #{desc => ?DESC(ssl_listener_options)}
@@ -481,7 +481,7 @@ fields(udp_listener) ->
 fields(dtls_listener) ->
     [{acceptors, sc(integer(), #{default => 16, desc => ?DESC(dtls_listener_acceptors)})}] ++
         fields(udp_listener) ++
-        [{dtls, sc(ref(dtls_opts), #{desc => ?DESC(dtls_listener_dtls_opts)})}];
+        [{dtls_options, sc(ref(dtls_opts), #{desc => ?DESC(dtls_listener_dtls_opts)})}];
 fields(udp_opts) ->
     [
         {active_n,
@@ -668,10 +668,10 @@ common_listener_opts() ->
     ].
 
 tcp_opts() ->
-    [{tcp, sc(ref(emqx_schema, "tcp_opts"), #{desc => ?DESC(tcp_listener_tcp_opts)})}].
+    [{tcp_options, sc(ref(emqx_schema, "tcp_opts"), #{desc => ?DESC(tcp_listener_tcp_opts)})}].
 
 udp_opts() ->
-    [{udp, sc(ref(udp_opts), #{})}].
+    [{udp_options, sc(ref(udp_opts), #{})}].
 
 proxy_protocol_opts() ->
     [

+ 3 - 3
apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl

@@ -211,11 +211,11 @@ t_gateway_exproto_with_ssl(_) ->
         name => <<"exproto">>,
         server => #{
             bind => <<"9100">>,
-            ssl => SslSvrOpts
+            ssl_options => SslSvrOpts
         },
         handler => #{
             address => <<"http://127.0.0.1:9001">>,
-            ssl => SslCliOpts#{enable => true}
+            ssl_options => SslCliOpts#{enable => true}
         },
         listeners => [
             #{name => <<"def">>, type => <<"tcp">>, bind => <<"7993">>}
@@ -228,7 +228,7 @@ t_gateway_exproto_with_ssl(_) ->
     GwConf2 = emqx_map_lib:deep_merge(GwConf, #{
         server => #{
             bind => <<"9200">>,
-            ssl => SslCliOpts
+            ssl_options => SslCliOpts
         }
     }),
     {200, _} = request(put, "/gateway/exproto", maps:without([name, listeners], GwConf2)),

+ 6 - 6
apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl

@@ -204,7 +204,7 @@ init_per_testcase(_CaseName, Conf) ->
 -define(CONF_STOMP_LISTENER_2, #{<<"bind">> => <<"61614">>}).
 -define(CONF_STOMP_LISTENER_SSL, #{
     <<"bind">> => <<"61614">>,
-    <<"ssl">> =>
+    <<"ssl_options">> =>
         #{
             <<"cacertfile">> => ?SVR_CA,
             <<"certfile">> => ?SVR_CERT,
@@ -213,7 +213,7 @@ init_per_testcase(_CaseName, Conf) ->
 }).
 -define(CONF_STOMP_LISTENER_SSL_2, #{
     <<"bind">> => <<"61614">>,
-    <<"ssl">> =>
+    <<"ssl_options">> =>
         #{
             <<"cacertfile">> => ?SVR_CA,
             <<"certfile">> => ?SVR_CERT2,
@@ -223,7 +223,7 @@ init_per_testcase(_CaseName, Conf) ->
 -define(CERTS_PATH(CertName), filename:join(["../../lib/emqx/etc/certs/", CertName])).
 -define(CONF_STOMP_LISTENER_SSL_PATH, #{
     <<"bind">> => <<"61614">>,
-    <<"ssl">> =>
+    <<"ssl_options">> =>
         #{
             <<"cacertfile">> => ?CERTS_PATH("cacert.pem"),
             <<"certfile">> => ?CERTS_PATH("cert.pem"),
@@ -409,7 +409,7 @@ t_load_gateway_with_certs_content(_) ->
     {ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
     assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
     SslConf = emqx_map_lib:deep_get(
-        [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl">>],
+        [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
         emqx:get_raw_config([gateway, stomp])
     ),
     ok = emqx_gateway_conf:unload_gateway(<<"stomp">>),
@@ -432,7 +432,7 @@ t_load_gateway_with_certs_content(_) ->
 %    {ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
 %    assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
 %    SslConf = emqx_map_lib:deep_get(
-%                [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl">>],
+%                [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
 %                emqx:get_raw_config([gateway, stomp])
 %               ),
 %    ok = emqx_gateway_conf:unload_gateway(<<"stomp">>),
@@ -467,7 +467,7 @@ t_add_listener_with_certs_content(_) ->
     ),
 
     SslConf = emqx_map_lib:deep_get(
-        [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl">>],
+        [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
         emqx:get_raw_config([gateway, stomp])
     ),
     ok = emqx_gateway_conf:remove_listener(