Skip to content

Commit

Permalink
Merge pull request #177 from illacloud/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
naj1n authored May 25, 2023
2 parents ae1f611 + 8d7f67e commit 2bff450
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/plugins/clickhouse/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down

0 comments on commit 2bff450

Please sign in to comment.