Skip to content

Commit 16927f2

Browse files
author
ultd
committed
added connecting with TLS to ILP capability
1 parent 591bcf2 commit 16927f2

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

client.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/ecdsa"
77
"crypto/elliptic"
88
"crypto/rand"
9+
"crypto/tls"
910
"database/sql"
1011
"encoding/base64"
1112
"errors"
@@ -23,6 +24,7 @@ type Config struct {
2324
ILPAuthPrivateKey string
2425
ILPAuthKid string
2526
PGConnStr string
27+
TLSConfig *tls.Config
2628
}
2729

2830
// Client struct represents a QuestDB client connection. This encompasses the InfluxDB Line
@@ -31,7 +33,7 @@ type Config struct {
3133
type Client struct {
3234
config Config
3335
// ilpConn is the TCP connection which allows Client to write data to QuestDB
34-
ilpConn *net.TCPConn
36+
ilpConn net.Conn
3537
// pgSqlDB is the Postgres SQL DB connection which allows to read/query data from QuestDB
3638
pgSqlDB *sql.DB
3739
}
@@ -57,6 +59,7 @@ func New(config Config) (*Client, error) {
5759

5860
var (
5961
ErrILPNetDial = errors.New("could not dial ilp host")
62+
ErrILPTLSDial = errors.New("could not dial tls host")
6063
ErrILPNetTCPAddrResolve = errors.New("could not resolve ilp host address")
6164
ErrPGOpen = errors.New("could not open postgres db")
6265
)
@@ -69,9 +72,18 @@ func (c *Client) Connect() error {
6972
return fmt.Errorf("%w: %v", ErrILPNetTCPAddrResolve, err)
7073
}
7174

72-
conn, err := net.DialTCP("tcp", nil, tcpAddr)
73-
if err != nil {
74-
return fmt.Errorf("%w: %v", ErrILPNetDial, err)
75+
if c.config.TLSConfig != nil {
76+
conn, err := tls.Dial("tcp", c.config.ILPHost, c.config.TLSConfig)
77+
if err != nil {
78+
return fmt.Errorf("%w: %v", ErrILPTLSDial, err)
79+
}
80+
c.ilpConn = conn
81+
} else {
82+
conn, err := net.DialTCP("tcp", nil, tcpAddr)
83+
if err != nil {
84+
return fmt.Errorf("%w: %v", ErrILPNetDial, err)
85+
}
86+
c.ilpConn = conn
7587
}
7688

7789
if c.config.ILPAuthPrivateKey != "" {
@@ -91,8 +103,8 @@ func (c *Client) Connect() error {
91103

92104
// send key ID
93105

94-
reader := bufio.NewReader(conn)
95-
_, err = conn.Write([]byte(c.config.ILPAuthKid + "\n"))
106+
reader := bufio.NewReader(c.ilpConn)
107+
_, err = c.ilpConn.Write([]byte(c.config.ILPAuthKid + "\n"))
96108
if err != nil {
97109
return fmt.Errorf("could not write to ilp tcp conn: %w", err)
98110
}
@@ -114,14 +126,12 @@ func (c *Client) Connect() error {
114126
return fmt.Errorf("could not ecdsa sign key: %w", err)
115127
}
116128
stdSig := append(a.Bytes(), b.Bytes()...)
117-
_, err = conn.Write([]byte(base64.StdEncoding.EncodeToString(stdSig) + "\n"))
129+
_, err = c.ilpConn.Write([]byte(base64.StdEncoding.EncodeToString(stdSig) + "\n"))
118130
if err != nil {
119131
return fmt.Errorf("could not write to ilp tcp conn: %w", err)
120132
}
121133
}
122134

123-
c.ilpConn = conn
124-
125135
db, err := sql.Open("postgres", c.config.PGConnStr)
126136
if err != nil {
127137
return fmt.Errorf("%w: %v", ErrPGOpen, err)

model.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ const (
4747
// CreateTableOptions struct is a struct which specifies options for creating
4848
// a QuestDB table
4949
type CreateTableOptions struct {
50-
PartitionBy PartitionOption
50+
PartitionBy PartitionOption
51+
// Deprecated: QuestDB >= v7.0.0 no longer requires this option
5152
MaxUncommittedRows int
52-
CommitLag string
53+
// Deprecated: QuestDB >= v7.0.0 no longer requires this option
54+
CommitLag string
5355
}
5456

5557
// String func prints out the CreateTableOptions in string format which would be appended

0 commit comments

Comments
 (0)