-
Notifications
You must be signed in to change notification settings - Fork 85
/
api_service.go
68 lines (61 loc) · 1.82 KB
/
api_service.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
package controllerv2
import (
gohttp "net/http"
bluemix "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"
)
//ResourceControllerAPIV2 is the resource client ...
type ResourceControllerAPIV2 interface {
ResourceServiceInstanceV2() ResourceServiceInstanceRepository
}
//ErrCodeAPICreation ...
const ErrCodeAPICreation = "APICreationError"
//resourceControllerService holds the client
type resourceControllerService struct {
*client.Client
}
//New ...
func New(sess *session.Session) (ResourceControllerAPIV2, error) {
config := sess.Config.Copy()
err := config.ValidateConfigForService(bluemix.ResourceControllerServicev2)
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{
"X-Original-User-Agent": []string{config.UserAgent},
"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.ResourceControllerEndpoint()
if err != nil {
return nil, err
}
config.Endpoint = &ep
}
return &resourceControllerService{
Client: client.New(config, bluemix.ResourceControllerServicev2, tokenRefreher),
}, nil
}
//ResourceController API
func (a *resourceControllerService) ResourceServiceInstanceV2() ResourceServiceInstanceRepository {
return newResourceServiceInstanceAPI(a.Client)
}