github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v6/shared/new_networking_client.go (about) 1 package shared 2 3 import ( 4 "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1" 5 "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/wrapper" 6 "code.cloudfoundry.org/cli/api/uaa" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/translatableerror" 9 ) 10 11 // NewNetworkingClient creates a new cfnetworking client. 12 func NewNetworkingClient(apiURL string, config command.Config, uaaClient *uaa.Client, ui command.UI) (*cfnetv1.Client, error) { 13 if apiURL == "" { 14 return nil, translatableerror.CFNetworkingEndpointNotFoundError{} 15 } 16 17 wrappers := []cfnetv1.ConnectionWrapper{} 18 19 verbose, location := config.Verbose() 20 if verbose { 21 wrappers = append(wrappers, wrapper.NewRequestLogger(ui.RequestLoggerTerminalDisplay())) 22 } 23 if location != nil { 24 wrappers = append(wrappers, wrapper.NewRequestLogger(ui.RequestLoggerFileWriter(location))) 25 } 26 27 authWrapper := wrapper.NewUAAAuthentication(uaaClient, config) 28 wrappers = append(wrappers, authWrapper) 29 30 wrappers = append(wrappers, wrapper.NewRetryRequest(config.RequestRetryCount())) 31 32 return cfnetv1.NewClient(cfnetv1.Config{ 33 AppName: config.BinaryName(), 34 AppVersion: config.BinaryVersion(), 35 DialTimeout: config.DialTimeout(), 36 SkipSSLValidation: config.SkipSSLValidation(), 37 URL: apiURL, 38 Wrappers: wrappers, 39 }), nil 40 }