forked from ShahabT/temporal-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
57 lines (49 loc) · 1.52 KB
/
client.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
package temporal_tests
import (
"crypto/tls"
"log"
"go.temporal.io/sdk/client"
)
func NewCloudClient(namespace string) (client.Client, error) {
if namespace == "" {
namespace = "shahab-test2"
}
namespace += ".temporal-dev"
//cloudHostPort := os.Getenv("TEMPORAL_CLOUD")
cloudHostPort := "tmprl-test.cloud:7233"
if cloudHostPort == "" {
log.Fatalln("TEMPORAL_CLOUD env var is not set")
}
// Get the key and cert from your env or local machine
clientKeyPath := "/Users/shahab/GolandProjects/certs/shahab-test.key"
clientCertPath := "/Users/shahab/GolandProjects/certs/shahab-test.pem"
// Specify the host and port of your Temporal Cloud Namespace
// Host and port format: namespace.unique_id.tmprl.cloud:port
hostPort := namespace + "." + cloudHostPort
// Use the crypto/tls package to create a cert object
cert, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
if err != nil {
log.Fatalln("Unable to load cert and key pair.", err)
}
// Add the cert to the tls certificates in the ConnectionOptions of the Client
c, err := client.Dial(client.Options{
HostPort: hostPort,
Namespace: namespace,
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{Certificates: []tls.Certificate{cert}},
},
})
if err != nil {
log.Fatalln("Unable to create client", err)
}
return c, err
}
func NewLocalClient(namespace string) (client.Client, error) {
c, err := client.Dial(client.Options{
Namespace: namespace,
})
if err != nil {
log.Fatalln("Unable to create client", err)
}
return c, err
}