github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+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 client.WrapConnection(newErrorWrapper()) //Pretty Sneaky, Sis.. 42 43 info, warnings, err := client.Info() 44 if err != nil { 45 return warnings, err 46 } 47 48 client.authorizationEndpoint = info.AuthorizationEndpoint 49 client.cloudControllerAPIVersion = info.APIVersion 50 client.dopplerEndpoint = info.DopplerEndpoint 51 client.minCLIVersion = info.MinCLIVersion 52 client.routingEndpoint = info.RoutingEndpoint 53 client.tokenEndpoint = info.TokenEndpoint 54 55 return warnings, nil 56 }