From 08acc7c15b945c713288470c2e61a57f327ac698 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Sun, 22 May 2022 07:46:01 +0200 Subject: [PATCH] config: add possibility to specify tls as bytes --- kafka/config_tls.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kafka/config_tls.go b/kafka/config_tls.go index 4c0657c..a70e264 100644 --- a/kafka/config_tls.go +++ b/kafka/config_tls.go @@ -1,11 +1,16 @@ package kafka +import "errors" + // TLSConfig to connect to Kafka via TLS type TLSConfig struct { Enabled bool `koanf:"enabled"` CaFilepath string `koanf:"caFilepath"` CertFilepath string `koanf:"certFilepath"` KeyFilepath string `koanf:"keyFilepath"` + Ca []byte + Cert []byte + Key []byte Passphrase string `koanf:"passphrase"` InsecureSkipTLSVerify bool `koanf:"insecureSkipTlsVerify"` } @@ -15,5 +20,9 @@ func (c *TLSConfig) SetDefaults() { } func (c *TLSConfig) Validate() error { + if (len(c.CaFilepath) > 0 || len(c.CertFilepath) > 0 || len(c.KeyFilepath) > 0) && + (len(c.Ca) > 0 || len(c.Cert) > 0 || len(c.Key) > 0) { + return errors.New("if caFilepath or certFilepath or keyFilepath is specified, ca, cert, key must be empty") + } return nil }