github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/actor/v3action/target.go (about)

     1  package v3action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     5  )
     6  
     7  type TargetSettings ccv3.TargetSettings
     8  
     9  // SetTarget targets the Cloud Controller using the client and sets target
    10  // information in the actor based on the response.
    11  func (actor Actor) SetTarget(settings TargetSettings) (Warnings, error) {
    12  	if actor.Config.Target() == settings.URL && actor.Config.SkipSSLValidation() == settings.SkipSSLValidation {
    13  		return nil, nil
    14  	}
    15  	var allWarnings Warnings
    16  
    17  	warnings, err := actor.CloudControllerClient.TargetCF(ccv3.TargetSettings(settings))
    18  	if err != nil {
    19  		return Warnings(warnings), err
    20  	}
    21  	allWarnings = Warnings(warnings)
    22  	var info ccv3.Info
    23  
    24  	info, _, warnings, err = actor.CloudControllerClient.GetInfo()
    25  	allWarnings = append(allWarnings, Warnings(warnings)...)
    26  	if err != nil {
    27  		return allWarnings, err
    28  	}
    29  	actor.Config.SetTargetInformation(settings.URL,
    30  		info.CloudControllerAPIVersion(),
    31  		info.UAA(),
    32  		"", // Oldest supported V3 version should be OK
    33  		info.Logging(),
    34  		info.Routing(),
    35  		settings.SkipSSLValidation,
    36  	)
    37  	actor.Config.SetTokenInformation("", "", "")
    38  
    39  	return Warnings(warnings), nil
    40  }
    41  
    42  // ClearTarget clears target information from the actor.
    43  func (actor Actor) ClearTarget() {
    44  	actor.Config.SetTargetInformation("", "", "", "", "", "", false)
    45  	actor.Config.SetTokenInformation("", "", "")
    46  }