forked from vxcontrol/rancher-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
39 lines (31 loc) · 803 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
package rancher
import (
"time"
rancherClient "github.com/rancher/go-rancher/v2"
)
type Client struct {
client *rancherClient.RancherClient
}
// NewClient returns a new client for the Rancher/Cattle API
func NewClient(rancherUrl string, rancherAccessKey string, rancherSecretKey string) (*Client, error) {
opts := &rancherClient.ClientOpts{
Url: rancherUrl,
AccessKey: rancherAccessKey,
SecretKey: rancherSecretKey,
Timeout: time.Second * 5,
}
var err error
var apiClient *rancherClient.RancherClient
maxTime := 10 * time.Second
for i := 1 * time.Second; i < maxTime; i *= time.Duration(2) {
apiClient, err = rancherClient.NewRancherClient(opts)
if err == nil {
break
}
time.Sleep(i)
}
if err != nil {
return nil, err
}
return &Client{apiClient}, nil
}