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

fix(connector): fix options handling for mongo connector

zhouzb 4 лет назад
Родитель
Сommit
4d92e2b6af

+ 1 - 1
apps/emqx/src/emqx_schema.erl

@@ -1163,7 +1163,7 @@ client_ssl_opts_schema(Defaults) ->
     common_ssl_opts_schema(Defaults) ++
     [ { "server_name_indication",
         sc(hoconsc:union([disable, string()]),
-           #{ default => disable
+           #{ nullable => true
             , desc =>
 """Specify the host name to be used in TLS Server Name Indication extension.<br>
 For instance, when connecting to \"server.example.net\", the genuine server

+ 4 - 3
apps/emqx_connector/src/emqx_connector_mongo.erl

@@ -105,7 +105,7 @@ on_start(InstId, Config = #{mongo_type := Type,
               sharded -> "starting_mongodb_sharded_connector"
           end,
     ?SLOG(info, #{msg => Msg, connector => InstId, config => Config}),
-    NConfig = may_parse_srv_and_txt_records(Config),
+    NConfig = #{hosts := Hosts} = may_parse_srv_and_txt_records(Config),
     SslOpts = case maps:get(enable, SSL) of
                   true ->
                       [{ssl, true},
@@ -119,6 +119,7 @@ on_start(InstId, Config = #{mongo_type := Type,
               end,
     Topology = maps:get(topology, NConfig, #{}),
     Opts = [{type, init_type(NConfig)},
+            {hosts, Hosts},
             {pool_size, PoolSize},
             {options, init_topology_options(maps:to_list(Topology), [])},
             {worker_options, init_worker_options(maps:to_list(NConfig), SslOpts)}],
@@ -193,9 +194,9 @@ mongo_query(Conn, find_one, Collection, Selector, Projector) ->
 mongo_query(_Conn, _Action, _Collection, _Selector, _Projector) ->
     ok.
 
-init_type(#{type := rs, replica_set_name := ReplicaSetName}) ->
+init_type(#{mongo_type := rs, replica_set_name := ReplicaSetName}) ->
     {rs, ReplicaSetName};
-init_type(#{type := Type}) ->
+init_type(#{mongo_type := Type}) ->
     Type.
 
 init_topology_options([{pool_size, Val} | R], Acc) ->

+ 2 - 4
apps/emqx_plugin_libs/src/emqx_plugin_libs_ssl.erl

@@ -73,10 +73,7 @@ save_files_return_opts(Options, Dir) ->
     Key = do_save_file(KeyFile, Dir),
     Cert = do_save_file(CertFile, Dir),
     CA = do_save_file(CAFile, Dir),
-    Verify = case GetD(verify, false) of
-                  false -> verify_none;
-                  _ -> verify_peer
-             end,
+    Verify = GetD(verify, verify_none),
     SNI = Get(server_name_indication),
     Versions = emqx_tls_lib:integral_versions(Get(tls_versions)),
     Ciphers = emqx_tls_lib:integral_ciphers(Versions, Get(ciphers)),
@@ -92,6 +89,7 @@ save_file(Param, SubDir) ->
    do_save_file(Param, Dir).
 
 filter([]) -> [];
+filter([{_, undefined} | T]) -> filter(T);
 filter([{_, ""} | T]) -> filter(T);
 filter([H | T]) -> [H | filter(T)].