github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/plugin/shared/new_client.go (about)

     1  package shared
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/plugin"
     5  	"code.cloudfoundry.org/cli/api/plugin/wrapper"
     6  	"code.cloudfoundry.org/cli/command"
     7  )
     8  
     9  // NewClients creates a new V2 Cloud Controller client and UAA client using the
    10  // passed in config.
    11  func NewClient(config command.Config, ui command.UI, skipSSLValidation bool) *plugin.Client {
    12  
    13  	verbose, location := config.Verbose()
    14  
    15  	pluginClient := plugin.NewClient(plugin.Config{
    16  		AppName:           config.BinaryName(),
    17  		AppVersion:        config.BinaryVersion(),
    18  		DialTimeout:       config.DialTimeout(),
    19  		SkipSSLValidation: skipSSLValidation,
    20  	})
    21  
    22  	if verbose {
    23  		pluginClient.WrapConnection(wrapper.NewRequestLogger(ui.RequestLoggerTerminalDisplay()))
    24  	}
    25  	if location != nil {
    26  		pluginClient.WrapConnection(wrapper.NewRequestLogger(ui.RequestLoggerFileWriter(location)))
    27  	}
    28  
    29  	pluginClient.WrapConnection(wrapper.NewRetryRequest(config.RequestRetryCount()))
    30  
    31  	return pluginClient
    32  }