-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.go
More file actions
48 lines (38 loc) · 1.07 KB
/
utils.go
File metadata and controls
48 lines (38 loc) · 1.07 KB
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
package controller
import (
"fmt"
"os"
"github.com/deis/builder/pkg/conf"
deis "github.com/deis/controller-sdk-go"
"github.com/deis/pkg/log"
)
const (
hostEnvName = "DEIS_CONTROLLER_SERVICE_HOST"
portEnvName = "DEIS_CONTROLLER_SERVICE_PORT"
)
// New creates a new SDK client configured as the builder.
func New() (*deis.Client, error) {
host := os.Getenv(hostEnvName)
port := os.Getenv(portEnvName)
client, err := deis.New(true, fmt.Sprintf("http://%s:%s/", host, port), "")
if err != nil {
return client, err
}
client.UserAgent = "deis-builder"
builderKey, err := conf.GetBuilderKey()
if err != nil {
return client, err
}
client.HooksToken = builderKey
return client, nil
}
// CheckAPICompat checks for API compatibility errors and warns about them.
func CheckAPICompat(c *deis.Client, err error) error {
if err == deis.ErrAPIMismatch {
log.Info("WARNING: SDK and Controller API versions do not match. SDK: %s Controller: %s",
deis.APIVersion, c.ControllerAPIVersion)
// API mismatch isn't fatal, so after warning continue on.
return nil
}
return err
}