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