forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iks.go
96 lines (88 loc) · 2.25 KB
/
iks.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package iks
import (
gohttp "net/http"
ibmcloud "github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/authentication"
"github.com/IBM-Cloud/bluemix-go/client"
"github.com/IBM-Cloud/bluemix-go/http"
"github.com/IBM-Cloud/bluemix-go/rest"
"github.com/IBM-Cloud/bluemix-go/session"
)
type KubernetesServiceAPI interface {
Zones() Zones
Regions() Regions
MachineTypes() MachineTypes
VLANs() VLANs
Clusters() Clusters
}
//ContainerService holds the client
type ksService struct {
*client.Client
}
// No auth session is required for region and zone calls
func NewSessionless(sess *session.Session) (KubernetesServiceAPI, error) {
config := sess.Config
if config.HTTPClient == nil {
config.HTTPClient = http.NewHTTPClient(config)
}
if config.Endpoint == nil {
ep, err := config.EndpointLocator.ContainerEndpoint()
if err != nil {
return nil, err
}
config.Endpoint = &ep
}
return &ksService{
Client: client.New(config, ibmcloud.ContainerService, nil),
}, nil
}
func New(sess *session.Session) (KubernetesServiceAPI, error) {
config := sess.Config.Copy()
err := config.ValidateConfigForService(ibmcloud.ContainerService)
if err != nil {
return nil, err
}
if config.HTTPClient == nil {
config.HTTPClient = http.NewHTTPClient(config)
}
tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
DefaultHeader: gohttp.Header{
"User-Agent": []string{http.UserAgent()},
},
HTTPClient: config.HTTPClient,
})
if err != nil {
return nil, err
}
if config.IAMAccessToken == "" {
err := authentication.PopulateTokens(tokenRefreher, config)
if err != nil {
return nil, err
}
}
if config.Endpoint == nil {
ep, err := config.EndpointLocator.ContainerEndpoint()
if err != nil {
return nil, err
}
config.Endpoint = &ep
}
return &ksService{
Client: client.New(config, ibmcloud.ContainerService, tokenRefreher),
}, nil
}
func (c *ksService) Zones() Zones {
return newZonesAPI(c.Client)
}
func (c *ksService) Regions() Regions {
return newRegionsAPI(c.Client)
}
func (c *ksService) MachineTypes() MachineTypes {
return newMachineTypesAPI(c.Client)
}
func (c *ksService) VLANs() VLANs {
return newVLANsAPI(c.Client)
}
func (c *ksService) Clusters() Clusters {
return newClusterAPI(c.Client)
}