forked from cloudfoundry/cli
/
target.go
52 lines (42 loc) · 1.78 KB
/
target.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
package v2action
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"code.cloudfoundry.org/cli/util/configv3"
)
type TargetSettings ccv2.TargetSettings
// ClearTarget clears target information from the actor.
func (actor Actor) ClearTarget() {
actor.Config.SetTargetInformation(configv3.TargetInformationArgs{})
actor.Config.SetTokenInformation("", "", "")
}
// MinCLIVersion returns the minimum CLI version that the Cloud Controller
// requires.
func (actor Actor) MinCLIVersion() string {
return actor.CloudControllerClient.MinCLIVersion()
}
// SetTarget targets the Cloud Controller using the client and sets target
// information in the actor based on the response.
func (actor Actor) SetTarget(settings TargetSettings) (Warnings, error) {
if actor.Config.Target() == settings.URL && actor.Config.SkipSSLValidation() == settings.SkipSSLValidation {
return nil, nil
}
warnings, err := actor.CloudControllerClient.TargetCF(ccv2.TargetSettings(settings))
if err != nil {
return Warnings(warnings), err
}
actor.Config.SetTargetInformation(configv3.TargetInformationArgs{
Api: actor.CloudControllerClient.API(),
ApiVersion: actor.CloudControllerClient.APIVersion(),
Auth: actor.CloudControllerClient.AuthorizationEndpoint(),
MinCLIVersion: actor.CloudControllerClient.MinCLIVersion(),
Doppler: actor.CloudControllerClient.DopplerEndpoint(),
LogCache: actor.CloudControllerClient.LogCacheEndpoint(),
Routing: actor.CloudControllerClient.RoutingEndpoint(),
SkipSSLValidation: settings.SkipSSLValidation,
})
actor.Config.SetTokenInformation("", "", "")
return Warnings(warnings), nil
}
func (actor Actor) AuthorizationEndpoint() string {
return actor.CloudControllerClient.AuthorizationEndpoint()
}