-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.go
69 lines (59 loc) · 2.05 KB
/
connect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package qdbinterface
import (
"fmt"
"log"
"time"
qdb "github.com/bureau14/qdb-api-go/v3"
)
// CreateHandle : creates a handle with config values
func CreateHandle(user, secret, uri, clusterPublicKeyFile string, maxInBufferSize uint, parallelismCount uint) (*qdb.HandleType, error) {
handle, err := qdb.NewHandle()
if err != nil {
return nil, err
}
// Set timeout
err = handle.SetTimeout(time.Duration(12) * time.Hour)
if err != nil {
return nil, err
}
// Set max_in_buffer_size
err = handle.SetClientMaxInBufSize(maxInBufferSize)
if err != nil {
err = fmt.Errorf("Invalid max in buffer size: %d", maxInBufferSize)
return nil, err
}
err = handle.SetClientMaxParallelism(parallelismCount)
if err != nil {
err = fmt.Errorf("Invalid max parallelism count: %d", parallelismCount)
return nil, err
}
if user != "" && secret != "" {
if clusterPublicKeyFile != "" {
// Set encryption if enabled server side
err = handle.SetEncryption(qdb.EncryptNone)
// add security if enabled server side
clusterKey, err := qdb.ClusterKeyFromFile(clusterPublicKeyFile)
if err != nil {
return nil, fmt.Errorf("Could not retrieve cluster key from file:%s", clusterPublicKeyFile)
}
err = handle.AddClusterPublicKey(clusterKey)
err = handle.AddUserCredentials(user, secret)
} else {
log.Printf("Warning: cannot connect user %s , cluster is not secured.", user)
}
}
// connect
err = handle.Connect(uri)
return &handle, err
}
// CreateHandle : creates a handle with config values
func CreateStatusHandle(uri string, restPrivateKeyFile string, clusterPublicKeyFile string, maxInBufferSize uint, parallelismCount uint) (*qdb.HandleType, error) {
if restPrivateKeyFile != "" {
user, secret, err := qdb.UserCredentialFromFile(restPrivateKeyFile)
if err != nil {
return nil, fmt.Errorf("Could not retrieve rest key from file:%s", restPrivateKeyFile)
}
return CreateHandle(user, secret, uri, clusterPublicKeyFile, maxInBufferSize, parallelismCount)
}
return CreateHandle("", "", uri, clusterPublicKeyFile, maxInBufferSize, parallelismCount)
}