From 4cbce87eac1ec8f312c725dd71c0f4678afa7c67 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Fri, 18 Feb 2022 12:36:35 +0300 Subject: [PATCH] [#340] Make nats tls and ca params optional nats.Connect returned error when tls and ca files were not set, what made these params required, but establishing of unsecured connection for debug is acceptable. Signed-off-by: Angira Kekteeva --- api/notifications/controller.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/notifications/controller.go b/api/notifications/controller.go index 7e054b4d8..06c34c8f5 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -29,11 +29,16 @@ func NewController(p *Options) (*Controller, error) { } ncopts := []nats.Option{ - nats.ClientCert(p.TLSCertFilepath, p.TLSAuthPrivateKeyFilePath), - nats.RootCAs(p.RootCAFiles...), nats.Timeout(p.Timeout), } + if len(p.TLSCertFilepath) != 0 && len(p.TLSAuthPrivateKeyFilePath) != 0 { + ncopts = append(ncopts, nats.ClientCert(p.TLSCertFilepath, p.TLSAuthPrivateKeyFilePath)) + } + if len(p.RootCAFiles) != 0 { + ncopts = append(ncopts, nats.RootCAs(p.RootCAFiles...)) + } + nc, err := nats.Connect(p.URL, ncopts...) if err != nil { return nil, err