github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/v3action/target.go (about) 1 package v3action 2 3 import ( 4 "strings" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 7 "code.cloudfoundry.org/cli/util/configv3" 8 ) 9 10 type TargetSettings ccv3.TargetSettings 11 12 // SetTarget targets the Cloud Controller using the client and sets target 13 // information in the actor based on the response. 14 func (actor Actor) SetTarget(settings TargetSettings) (Warnings, error) { 15 if actor.Config.Target() == settings.URL && actor.Config.SkipSSLValidation() == settings.SkipSSLValidation { 16 return nil, nil 17 } 18 19 info, warnings, err := actor.CloudControllerClient.TargetCF(ccv3.TargetSettings(settings)) 20 if err != nil { 21 return Warnings(warnings), err 22 } 23 //TODO Remove this condition when earliest supportest CAPI is 1.87.0 24 //We have to do this because the current legacy supported CAPI version as of 2020 does not display the log cache url, this will break if a foundation on legacy CAPI have non-standard logcache urls 25 26 logCacheUrl := info.LogCache() 27 if logCacheUrl == "" { 28 logCacheUrl = strings.Replace(settings.URL, "api", "log-cache", 1) 29 } 30 actor.Config.SetTargetInformation(configv3.TargetInformationArgs{ 31 Api: settings.URL, 32 ApiVersion: info.CloudControllerAPIVersion(), 33 Auth: info.Login(), 34 MinCLIVersion: "", // Oldest supported V3 version should be OK 35 Doppler: info.Logging(), 36 LogCache: logCacheUrl, 37 Routing: info.Routing(), 38 SkipSSLValidation: settings.SkipSSLValidation, 39 }) 40 actor.Config.SetTokenInformation("", "", "") 41 42 return Warnings(warnings), nil 43 } 44 45 // ClearTarget clears target information from the actor. 46 func (actor Actor) ClearTarget() { 47 actor.Config.SetTargetInformation(configv3.TargetInformationArgs{}) 48 actor.Config.SetTokenInformation("", "", "") 49 }