-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
45 lines (41 loc) · 907 Bytes
/
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
package registry
import (
"github.com/buckhx/safari-zone/proto/pbf"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type Client struct {
pbf.RegistryClient
*grpc.ClientConn
addr string
}
func Dial(addr string) (*Client, error) {
//creds := auth.AccessCredentials(tok)
opts := []grpc.DialOption{
grpc.WithInsecure(),
//grpc.WithPerRPCCredentials(creds),
}
conn, err := grpc.Dial(addr, opts...)
if err != nil {
return nil, err
}
cli := pbf.NewRegistryClient(conn)
return &Client{
RegistryClient: cli,
ClientConn: conn,
addr: addr,
//tok: tok,
}, nil
}
func FetchAccessToken(addr, key, secret string) (string, error) {
reg, err := Dial(addr)
if err != nil {
return "", err
}
defer reg.Close()
tok, err := reg.Access(context.Background(), &pbf.Token{Key: key, Secret: secret})
if err != nil {
return "", err
}
return tok.Access, nil
}