forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
76 lines (63 loc) · 1.57 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package client
import (
"fmt"
"os"
"strconv"
"go.pedge.io/proto/version"
"google.golang.org/grpc"
"github.com/pachyderm/pachyderm/src/client/pfs"
"github.com/pachyderm/pachyderm/src/client/pps"
)
const (
// MajorVersion is the current major version for pachyderm.
MajorVersion = 1
// MinorVersion is the current minor version for pachyderm.
MinorVersion = 0
// AdditionalVersion will be "dev" is this is a development branch, "" otherwise.
AdditionalVersion = ""
)
var (
// Version is the current version for pachyderm.
Version = &protoversion.Version{
Major: MajorVersion,
Minor: MinorVersion,
Micro: getMicroVersion(),
Additional: AdditionalVersion,
}
)
type PfsAPIClient pfs.APIClient
type PpsAPIClient pps.APIClient
type APIClient struct {
PfsAPIClient
PpsAPIClient
}
func NewFromAddress(pachAddr string) (*APIClient, error) {
clientConn, err := grpc.Dial(pachAddr, grpc.WithInsecure())
if err != nil {
return nil, err
}
return &APIClient{
pfs.NewAPIClient(clientConn),
pps.NewAPIClient(clientConn),
}, nil
}
func New() (*APIClient, error) {
pachAddr := os.Getenv("PACHD_PORT_650_TCP_ADDR")
if pachAddr == "" {
return nil, fmt.Errorf("PACHD_PORT_650_TCP_ADDR not set")
}
return NewFromAddress(fmt.Sprintf("%v:650", pachAddr))
}
func getMicroVersion() (v uint32) {
value := os.Getenv("BUILD_NUMBER")
if value == "" {
v = 0
} else {
number, err := strconv.Atoi(value)
if err != nil {
panic(fmt.Sprintf("Invalid build number provided via BUILD_NUMBER env variable: (%v)\n", value))
}
v = uint32(number)
}
return v
}