From f1c1ece5004dd84cfd83b9748c3ddadb2a8cc7a1 Mon Sep 17 00:00:00 2001 From: Jay D Date: Thu, 25 May 2023 16:41:12 +0800 Subject: [PATCH] fix: update clickhouse connection method --- pkg/plugins/clickhouse/base.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/plugins/clickhouse/base.go b/pkg/plugins/clickhouse/base.go index 9919fec1..f0a42e5c 100644 --- a/pkg/plugins/clickhouse/base.go +++ b/pkg/plugins/clickhouse/base.go @@ -36,8 +36,21 @@ func (c *Connector) getConnectionWithOptions(resourceOptions map[string]interfac return nil, err } - t := &tls.Config{} + opts := clickhouse.Options{ + Addr: []string{fmt.Sprintf("%s:%d", c.ResourceOpts.Host, c.ResourceOpts.Port)}, + Auth: clickhouse.Auth{ + Database: c.ResourceOpts.DatabaseName, + Username: c.ResourceOpts.Username, + Password: c.ResourceOpts.Password, + }, + } + + if c.ResourceOpts.SSL.SSL { + t := &tls.Config{InsecureSkipVerify: false} + opts.TLS = t + } if c.ResourceOpts.SSL.SSL && c.ResourceOpts.SSL.SelfSigned { + t := &tls.Config{} pool := x509.NewCertPool() if ok := pool.AppendCertsFromPEM([]byte(c.ResourceOpts.SSL.CACert)); !ok { return nil, errors.New("clickhouse SSL/TLS Connection failed") @@ -52,17 +65,10 @@ func (c *Connector) getConnectionWithOptions(resourceOptions map[string]interfac } t.Certificates = []tls.Certificate{cert} } + opts.TLS = t } - db := clickhouse.OpenDB(&clickhouse.Options{ - Addr: []string{fmt.Sprintf("%s:%d", c.ResourceOpts.Host, c.ResourceOpts.Port)}, - Auth: clickhouse.Auth{ - Database: c.ResourceOpts.DatabaseName, - Username: c.ResourceOpts.Username, - Password: c.ResourceOpts.Password, - }, - TLS: t, - }) + db := clickhouse.OpenDB(&opts) return db, nil }