Restore secure option to control tls in nats_consumer
This commit is contained in:
parent
be7abd9959
commit
ffe9494663
|
@ -21,6 +21,9 @@ instances of telegraf can read from a NATS cluster in parallel.
|
||||||
# username = ""
|
# username = ""
|
||||||
# password = ""
|
# password = ""
|
||||||
|
|
||||||
|
## Use Transport Layer Security
|
||||||
|
# secure = false
|
||||||
|
|
||||||
## Optional TLS Config
|
## Optional TLS Config
|
||||||
# tls_ca = "/etc/telegraf/ca.pem"
|
# tls_ca = "/etc/telegraf/ca.pem"
|
||||||
# tls_cert = "/etc/telegraf/cert.pem"
|
# tls_cert = "/etc/telegraf/cert.pem"
|
||||||
|
|
|
@ -35,11 +35,10 @@ type natsConsumer struct {
|
||||||
QueueGroup string `toml:"queue_group"`
|
QueueGroup string `toml:"queue_group"`
|
||||||
Subjects []string `toml:"subjects"`
|
Subjects []string `toml:"subjects"`
|
||||||
Servers []string `toml:"servers"`
|
Servers []string `toml:"servers"`
|
||||||
|
Secure bool `toml:"secure"`
|
||||||
Username string `toml:"username"`
|
Username string `toml:"username"`
|
||||||
Password string `toml:"password"`
|
Password string `toml:"password"`
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
// Legacy; Should be deprecated
|
|
||||||
Secure bool `toml:"secure"`
|
|
||||||
|
|
||||||
// Client pending limits:
|
// Client pending limits:
|
||||||
PendingMessageLimit int `toml:"pending_message_limit"`
|
PendingMessageLimit int `toml:"pending_message_limit"`
|
||||||
|
@ -66,8 +65,7 @@ type natsConsumer struct {
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
## urls of NATS servers
|
## urls of NATS servers
|
||||||
servers = ["nats://localhost:4222"]
|
servers = ["nats://localhost:4222"]
|
||||||
## Deprecated: Use Transport Layer Security
|
|
||||||
secure = false
|
|
||||||
## subject(s) to consume
|
## subject(s) to consume
|
||||||
subjects = ["telegraf"]
|
subjects = ["telegraf"]
|
||||||
## name a queue group
|
## name a queue group
|
||||||
|
@ -77,6 +75,9 @@ var sampleConfig = `
|
||||||
# username = ""
|
# username = ""
|
||||||
# password = ""
|
# password = ""
|
||||||
|
|
||||||
|
## Use Transport Layer Security
|
||||||
|
# secure = false
|
||||||
|
|
||||||
## Optional TLS Config
|
## Optional TLS Config
|
||||||
# tls_ca = "/etc/telegraf/ca.pem"
|
# tls_ca = "/etc/telegraf/ca.pem"
|
||||||
# tls_cert = "/etc/telegraf/cert.pem"
|
# tls_cert = "/etc/telegraf/cert.pem"
|
||||||
|
@ -147,18 +148,14 @@ func (n *natsConsumer) Start(acc telegraf.Accumulator) error {
|
||||||
opts.Password = n.Password
|
opts.Password = n.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
// override TLS, if it was specified
|
if n.Secure {
|
||||||
tlsConfig, err := n.ClientConfig.TLSConfig()
|
tlsConfig, err := n.ClientConfig.TLSConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tlsConfig != nil {
|
|
||||||
// set NATS connection TLS options
|
|
||||||
opts.Secure = true
|
opts.Secure = true
|
||||||
opts.TLSConfig = tlsConfig
|
opts.TLSConfig = tlsConfig
|
||||||
} else {
|
|
||||||
// should be deprecated; use TLS
|
|
||||||
opts.Secure = n.Secure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.conn == nil || n.conn.IsClosed() {
|
if n.conn == nil || n.conn.IsClosed() {
|
||||||
|
|
Loading…
Reference in New Issue