forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.go
46 lines (39 loc) · 1.32 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
package v3action
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
)
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) {
if actor.Config.Target() == settings.URL && actor.Config.SkipSSLValidation() == settings.SkipSSLValidation {
return nil, nil
}
var allWarnings Warnings
warnings, err := actor.CloudControllerClient.TargetCF(ccv3.TargetSettings(settings))
if err != nil {
return Warnings(warnings), err
}
allWarnings = Warnings(warnings)
var info ccv3.Info
info, _, warnings, err = actor.CloudControllerClient.GetInfo()
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return allWarnings, err
}
actor.Config.SetTargetInformation(settings.URL,
info.CloudControllerAPIVersion(),
info.UAA(),
"", // Oldest supported V3 version should be OK
info.Logging(),
info.Routing(),
settings.SkipSSLValidation,
)
actor.Config.SetTokenInformation("", "", "")
return Warnings(warnings), nil
}
// ClearTarget clears target information from the actor.
func (actor Actor) ClearTarget() {
actor.Config.SetTargetInformation("", "", "", "", "", "", false)
actor.Config.SetTokenInformation("", "", "")
}