diff --git a/pubsub/mqtt/mqtt.go b/pubsub/mqtt/mqtt.go index d11c51e06..dd7a8f144 100644 --- a/pubsub/mqtt/mqtt.go +++ b/pubsub/mqtt/mqtt.go @@ -16,7 +16,6 @@ package mqtt import ( "context" "crypto/tls" - "encoding/pem" "errors" "fmt" "net/url" @@ -64,13 +63,6 @@ func NewMQTTPubSub(logger logger.Logger) pubsub.PubSub { } } -// isValidPEM validates the provided input has PEM formatted block. -func isValidPEM(val string) bool { - block, _ := pem.Decode([]byte(val)) - - return block != nil -} - // Init parses metadata and creates a new Pub Sub client. func (m *mqttPubSub) Init(metadata pubsub.Metadata) error { mqttMeta, err := parseMQTTMetaData(metadata, m.logger) diff --git a/pubsub/rabbitmq/rabbitmq_test.go b/pubsub/rabbitmq/rabbitmq_test.go index 254f8b27c..db3b91d56 100644 --- a/pubsub/rabbitmq/rabbitmq_test.go +++ b/pubsub/rabbitmq/rabbitmq_test.go @@ -38,7 +38,7 @@ func newRabbitMQTest(broker *rabbitMQInMemoryBroker) pubsub.PubSub { return &rabbitMQ{ declaredExchanges: make(map[string]bool), logger: logger.NewLogger("test"), - connectionDial: func(schema, uri string, tlsCfg *tls.Config) (rabbitMQConnectionBroker, rabbitMQChannelBroker, error) { + connectionDial: func(protocol, uri string, tlsCfg *tls.Config) (rabbitMQConnectionBroker, rabbitMQChannelBroker, error) { broker.connectCount++ return broker, broker, nil diff --git a/pubsub/tls.go b/pubsub/tls.go index 848ac4d67..fa031696e 100644 --- a/pubsub/tls.go +++ b/pubsub/tls.go @@ -8,6 +8,7 @@ import ( "fmt" ) +// TLSProperties is a struct that contains the TLS properties. type TLSProperties struct { CACert string ClientCert string @@ -15,9 +16,12 @@ type TLSProperties struct { } const ( - CACert = "caCert" + // CACert is the metadata key name for the CA certificate. + CACert = "caCert" + // ClientCert is the metadata key name for the client certificate. ClientCert = "clientCert" - ClientKey = "clientKey" + // ClientKey is the metadata key name for the client key. + ClientKey = "clientKey" ) // TLS takes a metadata object and returns the TLSProperties configured. @@ -46,13 +50,14 @@ func TLS(metadata map[string]string) (TLSProperties, error) { return cfg, nil } +// ConvertTLSPropertiesToTLSConfig converts the TLSProperties to a tls.Config. func ConvertTLSPropertiesToTLSConfig(properties TLSProperties) (*tls.Config, error) { tlsConfig := new(tls.Config) if properties.ClientCert != "" && properties.ClientKey != "" { cert, err := tls.X509KeyPair([]byte(properties.ClientCert), []byte(properties.ClientKey)) if err != nil { - return &tls.Config{}, fmt.Errorf("unable to load client certificate and key pair. Err: %v", err) + return tlsConfig, fmt.Errorf("unable to load client certificate and key pair. Err: %v", err) } tlsConfig.Certificates = []tls.Certificate{cert} } @@ -60,7 +65,7 @@ func ConvertTLSPropertiesToTLSConfig(properties TLSProperties) (*tls.Config, err if properties.CACert != "" { tlsConfig.RootCAs = x509.NewCertPool() if ok := tlsConfig.RootCAs.AppendCertsFromPEM([]byte(properties.CACert)); !ok { - return &tls.Config{}, fmt.Errorf("unable to load CA certificate") + return tlsConfig, fmt.Errorf("unable to load CA certificate") } } diff --git a/pubsub/tls_test.go b/pubsub/tls_test.go index 0f0847c4a..fab646be4 100644 --- a/pubsub/tls_test.go +++ b/pubsub/tls_test.go @@ -3,8 +3,9 @@ package pubsub import ( "crypto/x509" "encoding/pem" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestConvertTLSPropertiesToTLSConfig(t *testing.T) {