github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/target.go (about)

     1  package ccv2
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
     8  	"github.com/tedsuo/rata"
     9  )
    10  
    11  // TargetSettings represents configuration for establishing a connection to the
    12  // Cloud Controller server.
    13  type TargetSettings struct {
    14  	// DialTimeout is the DNS timeout used to make all requests to the Cloud
    15  	// Controller.
    16  	DialTimeout time.Duration
    17  
    18  	// SkipSSLValidation controls whether a client verifies the server's
    19  	// certificate chain and host name. If SkipSSLValidation is true, TLS accepts
    20  	// any certificate presented by the server and any host name in that
    21  	// certificate for *all* client requests going forward.
    22  	//
    23  	// In this mode, TLS is susceptible to man-in-the-middle attacks. This should
    24  	// be used only for testing.
    25  	SkipSSLValidation bool
    26  
    27  	// URL is a fully qualified URL to the Cloud Controller API.
    28  	URL string
    29  }
    30  
    31  // TargetCF sets the client to use the Cloud Controller specified in the
    32  // configuration. Any other configuration is also applied to the client.
    33  func (client *Client) TargetCF(settings TargetSettings) (Warnings, error) {
    34  	client.cloudControllerURL = settings.URL
    35  	client.router = rata.NewRequestGenerator(settings.URL, internal.APIRoutes)
    36  
    37  	client.connection = cloudcontroller.NewConnection(cloudcontroller.Config{
    38  		DialTimeout:       settings.DialTimeout,
    39  		SkipSSLValidation: settings.SkipSSLValidation,
    40  	})
    41  
    42  	for _, wrapper := range client.wrappers {
    43  		client.connection = wrapper.Wrap(client.connection)
    44  	}
    45  
    46  	info, warnings, err := client.Info()
    47  	if err != nil {
    48  		return warnings, err
    49  	}
    50  
    51  	client.authorizationEndpoint = info.AuthorizationEndpoint
    52  	client.cloudControllerAPIVersion = info.APIVersion
    53  	client.dopplerEndpoint = info.DopplerEndpoint
    54  	client.minCLIVersion = info.MinCLIVersion
    55  	client.routingEndpoint = info.RoutingEndpoint
    56  	client.tokenEndpoint = info.TokenEndpoint
    57  
    58  	return warnings, nil
    59  }