fix(connector): fix options handling for mongo connector

This commit is contained in:
zhouzb 2021-11-23 20:01:21 +08:00
parent ef0e440d27
commit 4d92e2b6af
3 changed files with 7 additions and 8 deletions

View File

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

View File

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

View File

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