From 4d92e2b6af82816d4700828e1d175d829b422142 Mon Sep 17 00:00:00 2001 From: zhouzb Date: Tue, 23 Nov 2021 20:01:21 +0800 Subject: [PATCH] fix(connector): fix options handling for mongo connector --- apps/emqx/src/emqx_schema.erl | 2 +- apps/emqx_connector/src/emqx_connector_mongo.erl | 7 ++++--- apps/emqx_plugin_libs/src/emqx_plugin_libs_ssl.erl | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index b7f3c5690..44662d9f7 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/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.
For instance, when connecting to \"server.example.net\", the genuine server diff --git a/apps/emqx_connector/src/emqx_connector_mongo.erl b/apps/emqx_connector/src/emqx_connector_mongo.erl index ad8d91f1c..c2d992cb6 100644 --- a/apps/emqx_connector/src/emqx_connector_mongo.erl +++ b/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) -> diff --git a/apps/emqx_plugin_libs/src/emqx_plugin_libs_ssl.erl b/apps/emqx_plugin_libs/src/emqx_plugin_libs_ssl.erl index b000a8be8..2bcf66763 100644 --- a/apps/emqx_plugin_libs/src/emqx_plugin_libs_ssl.erl +++ b/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)].