/
clients.go
39 lines (32 loc) · 914 Bytes
/
clients.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
package client
import (
"fmt"
"github.com/authzed/authzed-go/v1"
"github.com/authzed/grpcutil"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"os"
)
func InitServer(spiceDBURL string, preSharedKey string) *authzed.Client {
SpiceDbClient, err := GetSpiceDbClient(spiceDBURL, preSharedKey)
if err != nil {
err := fmt.Errorf("%v", err)
fmt.Println(err)
os.Exit(1)
}
return SpiceDbClient
}
func GetSpiceDbClient(endpoint string, presharedKey string) (*authzed.Client, error) {
fmt.Println("Attempting to connect to spicedb...")
defer func() {
fmt.Println("Connection to spicedb established")
}()
var opts []grpc.DialOption
opts = append(opts, grpc.WithBlock())
opts = append(opts, grpcutil.WithInsecureBearerToken(presharedKey))
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
return authzed.NewClient(
endpoint,
opts...,
)
}