|
@@ -80,7 +80,7 @@ fields(config) ->
|
|
|
|
|
|
|
|
{pool_size, fun emqx_connector_schema_lib:pool_size/1},
|
|
{pool_size, fun emqx_connector_schema_lib:pool_size/1},
|
|
|
{auto_reconnect, fun emqx_connector_schema_lib:auto_reconnect/1}
|
|
{auto_reconnect, fun emqx_connector_schema_lib:auto_reconnect/1}
|
|
|
- ].
|
|
|
|
|
|
|
+ ] ++ emqx_connector_schema_lib:ssl_fields().
|
|
|
|
|
|
|
|
servers() ->
|
|
servers() ->
|
|
|
Meta = #{desc => ?DESC("servers")},
|
|
Meta = #{desc => ?DESC("servers")},
|
|
@@ -98,7 +98,8 @@ on_start(
|
|
|
servers := BinServers,
|
|
servers := BinServers,
|
|
|
access_key := AccessKey,
|
|
access_key := AccessKey,
|
|
|
secret_key := SecretKey,
|
|
secret_key := SecretKey,
|
|
|
- security_token := SecurityToken
|
|
|
|
|
|
|
+ security_token := SecurityToken,
|
|
|
|
|
+ ssl := SSLOptsMap
|
|
|
} = Config
|
|
} = Config
|
|
|
) ->
|
|
) ->
|
|
|
?SLOG(info, #{
|
|
?SLOG(info, #{
|
|
@@ -113,13 +114,15 @@ on_start(
|
|
|
ClientId = client_id(InstanceId),
|
|
ClientId = client_id(InstanceId),
|
|
|
ACLInfo = acl_info(AccessKey, SecretKey, SecurityToken),
|
|
ACLInfo = acl_info(AccessKey, SecretKey, SecurityToken),
|
|
|
Namespace = maps:get(namespace, Config, <<>>),
|
|
Namespace = maps:get(namespace, Config, <<>>),
|
|
|
- ClientCfg = #{acl_info => ACLInfo, namespace => Namespace},
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ClientCfg0 = #{acl_info => ACLInfo, namespace => Namespace},
|
|
|
|
|
+ SSLOpts = emqx_tls_lib:to_client_opts(SSLOptsMap),
|
|
|
|
|
+ ClientCfg = emqx_utils_maps:put_if(ClientCfg0, ssl_opts, SSLOpts, SSLOpts =/= []),
|
|
|
State = #{
|
|
State = #{
|
|
|
client_id => ClientId,
|
|
client_id => ClientId,
|
|
|
acl_info => ACLInfo,
|
|
acl_info => ACLInfo,
|
|
|
namespace => Namespace,
|
|
namespace => Namespace,
|
|
|
- installed_channels => #{}
|
|
|
|
|
|
|
+ installed_channels => #{},
|
|
|
|
|
+ ssl_opts => SSLOpts
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
ok = emqx_resource:allocate_resource(InstanceId, client_id, ClientId),
|
|
ok = emqx_resource:allocate_resource(InstanceId, client_id, ClientId),
|
|
@@ -142,12 +145,13 @@ on_add_channel(
|
|
|
#{
|
|
#{
|
|
|
installed_channels := InstalledChannels,
|
|
installed_channels := InstalledChannels,
|
|
|
namespace := Namespace,
|
|
namespace := Namespace,
|
|
|
- acl_info := ACLInfo
|
|
|
|
|
|
|
+ acl_info := ACLInfo,
|
|
|
|
|
+ ssl_opts := SSLOpts
|
|
|
} = OldState,
|
|
} = OldState,
|
|
|
ChannelId,
|
|
ChannelId,
|
|
|
ChannelConfig
|
|
ChannelConfig
|
|
|
) ->
|
|
) ->
|
|
|
- {ok, ChannelState} = create_channel_state(ChannelConfig, ACLInfo, Namespace),
|
|
|
|
|
|
|
+ {ok, ChannelState} = create_channel_state(ChannelConfig, ACLInfo, Namespace, SSLOpts),
|
|
|
NewInstalledChannels = maps:put(ChannelId, ChannelState, InstalledChannels),
|
|
NewInstalledChannels = maps:put(ChannelId, ChannelState, InstalledChannels),
|
|
|
%% Update state
|
|
%% Update state
|
|
|
NewState = OldState#{installed_channels => NewInstalledChannels},
|
|
NewState = OldState#{installed_channels => NewInstalledChannels},
|
|
@@ -156,7 +160,8 @@ on_add_channel(
|
|
|
create_channel_state(
|
|
create_channel_state(
|
|
|
#{parameters := Conf} = _ChannelConfig,
|
|
#{parameters := Conf} = _ChannelConfig,
|
|
|
ACLInfo,
|
|
ACLInfo,
|
|
|
- Namespace
|
|
|
|
|
|
|
+ Namespace,
|
|
|
|
|
+ SSLOpts
|
|
|
) ->
|
|
) ->
|
|
|
#{
|
|
#{
|
|
|
topic := Topic,
|
|
topic := Topic,
|
|
@@ -164,7 +169,7 @@ create_channel_state(
|
|
|
strategy := Strategy
|
|
strategy := Strategy
|
|
|
} = Conf,
|
|
} = Conf,
|
|
|
TopicTks = emqx_placeholder:preproc_tmpl(Topic),
|
|
TopicTks = emqx_placeholder:preproc_tmpl(Topic),
|
|
|
- ProducerOpts = make_producer_opts(Conf, ACLInfo, Namespace, Strategy),
|
|
|
|
|
|
|
+ ProducerOpts = make_producer_opts(Conf, ACLInfo, Namespace, Strategy, SSLOpts),
|
|
|
Templates = parse_template(Conf),
|
|
Templates = parse_template(Conf),
|
|
|
DispatchStrategy = parse_dispatch_strategy(Strategy),
|
|
DispatchStrategy = parse_dispatch_strategy(Strategy),
|
|
|
State = #{
|
|
State = #{
|
|
@@ -407,9 +412,10 @@ make_producer_opts(
|
|
|
},
|
|
},
|
|
|
ACLInfo,
|
|
ACLInfo,
|
|
|
Namespace,
|
|
Namespace,
|
|
|
- Strategy
|
|
|
|
|
|
|
+ Strategy,
|
|
|
|
|
+ SSLOpts
|
|
|
) ->
|
|
) ->
|
|
|
- #{
|
|
|
|
|
|
|
+ ProducerOpts = #{
|
|
|
tcp_opts => [{sndbuf, SendBuff}],
|
|
tcp_opts => [{sndbuf, SendBuff}],
|
|
|
ref_topic_route_interval => RefreshInterval,
|
|
ref_topic_route_interval => RefreshInterval,
|
|
|
acl_info => emqx_secret:wrap(ACLInfo),
|
|
acl_info => emqx_secret:wrap(ACLInfo),
|
|
@@ -419,7 +425,8 @@ make_producer_opts(
|
|
|
roundrobin -> roundrobin;
|
|
roundrobin -> roundrobin;
|
|
|
_ -> key_dispatch
|
|
_ -> key_dispatch
|
|
|
end
|
|
end
|
|
|
- }.
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ emqx_utils_maps:put_if(ProducerOpts, ssl_opts, SSLOpts, SSLOpts =/= []).
|
|
|
|
|
|
|
|
acl_info(<<>>, _, _) ->
|
|
acl_info(<<>>, _, _) ->
|
|
|
#{};
|
|
#{};
|