-
Notifications
You must be signed in to change notification settings - Fork 927
/
client.go
61 lines (50 loc) · 1.82 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
package helpers
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
ccWrapper "code.cloudfoundry.org/cli/api/cloudcontroller/wrapper"
"code.cloudfoundry.org/cli/api/uaa"
uaaWrapper "code.cloudfoundry.org/cli/api/uaa/wrapper"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/configv3"
)
// CreateCCV2Client constructs a client object able to communicate with the
// cloudcontroller V2 API.
func CreateCCV2Client() (*ccv2.Client, error) {
config, err := configv3.LoadConfig(configv3.FlagOverride{})
if err != nil {
return nil, err
}
ccWrappers := []ccv2.ConnectionWrapper{}
authWrapper := ccWrapper.NewUAAAuthentication(nil, config)
ccWrappers = append(ccWrappers, authWrapper)
ccWrappers = append(ccWrappers, ccWrapper.NewRetryRequest(config.RequestRetryCount()))
ccClient := ccv2.NewClient(ccv2.Config{
AppName: config.BinaryName(),
AppVersion: config.BinaryVersion(),
JobPollingTimeout: config.OverallPollingTimeout(),
JobPollingInterval: config.PollingInterval(),
Wrappers: ccWrappers,
})
_, err = ccClient.TargetCF(ccv2.TargetSettings{
URL: config.Target(),
SkipSSLValidation: config.SkipSSLValidation(),
DialTimeout: config.DialTimeout(),
})
if err != nil {
return nil, err
}
if ccClient.AuthorizationEndpoint() == "" {
return nil, translatableerror.AuthorizationEndpointNotFoundError{}
}
uaaClient := uaa.NewClient(config)
uaaAuthWrapper := uaaWrapper.NewUAAAuthentication(nil, config)
uaaClient.WrapConnection(uaaAuthWrapper)
uaaClient.WrapConnection(uaaWrapper.NewRetryRequest(config.RequestRetryCount()))
err = uaaClient.SetupResources(ccClient.AuthorizationEndpoint())
if err != nil {
return nil, err
}
uaaAuthWrapper.SetClient(uaaClient)
authWrapper.SetClient(uaaClient)
return ccClient, nil
}