forked from cloudfoundry/cli
/
target.go
36 lines (31 loc) · 1.22 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
package v7action
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/util/configv3"
)
type TargetSettings ccv3.TargetSettings
// 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) {
rootInfo, warnings, err := actor.CloudControllerClient.TargetCF(ccv3.TargetSettings(settings))
if err != nil {
return Warnings(warnings), err
}
actor.Config.SetTargetInformation(configv3.TargetInformationArgs{
Api: settings.URL,
ApiVersion: rootInfo.CloudControllerAPIVersion(),
Auth: rootInfo.Login(),
MinCLIVersion: "", // Oldest supported V3 version should be OK
Doppler: rootInfo.Logging(),
LogCache: rootInfo.LogCache(),
Routing: rootInfo.Routing(),
SkipSSLValidation: settings.SkipSSLValidation,
})
actor.Config.SetTokenInformation("", "", "")
return Warnings(warnings), nil
}
// ClearTarget clears target information from the actor.
func (actor Actor) ClearTarget() {
actor.Config.SetTargetInformation(configv3.TargetInformationArgs{})
actor.Config.SetTokenInformation("", "", "")
}