[#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 <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-02-18 12:36:35 +03:00 committed by LeL
parent e0c6544567
commit 4cbce87eac

View file

@ -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