-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
55 lines (44 loc) · 1.11 KB
/
main.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
package main
import (
"crypto/x509"
"flag"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/couchbase/gocb/v2"
)
func main() {
connection := flag.String("connection", "", "Hostname")
username := flag.String("username", "", "Username")
password := flag.String("password", "", "Password")
cafile := flag.String("cafile", "", "CA filename")
bucketName := flag.String("bucket", "", "Bucket name")
flag.Parse()
options := gocb.ClusterOptions{
Username: *username,
Password: *password,
}
if *cafile != "" {
ca, err := ioutil.ReadFile(*cafile)
if err != nil {
fmt.Println("failed to load CA:", err)
os.Exit(1)
}
caCerts := x509.NewCertPool()
caCerts.AppendCertsFromPEM(ca)
options.SecurityConfig = gocb.SecurityConfig{
TLSRootCAs: caCerts,
}
}
cluster, err := gocb.Connect(*connection, options)
if err != nil {
fmt.Println("failed to open connection:", err)
os.Exit(1)
}
bucket := cluster.Bucket(*bucketName)
if err := bucket.WaitUntilReady(20*time.Second, nil); err != nil {
fmt.Println("failed to wait for ready bucket:", err)
os.Exit(1)
}
}