github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v6/shared/new_v3_based_clients.go (about) 1 package shared 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 5 ccWrapper "code.cloudfoundry.org/cli/api/cloudcontroller/wrapper" 6 "code.cloudfoundry.org/cli/api/uaa" 7 uaaWrapper "code.cloudfoundry.org/cli/api/uaa/wrapper" 8 "code.cloudfoundry.org/cli/command" 9 "code.cloudfoundry.org/cli/command/translatableerror" 10 ) 11 12 // NewV3BasedClients creates a new V3 Cloud Controller client and UAA client using the 13 // passed in config. 14 func NewV3BasedClients(config command.Config, ui command.UI, targetCF bool) (*ccv3.Client, *uaa.Client, error) { 15 ccWrappers := []ccv3.ConnectionWrapper{} 16 17 verbose, location := config.Verbose() 18 if verbose { 19 ccWrappers = append(ccWrappers, ccWrapper.NewRequestLogger(ui.RequestLoggerTerminalDisplay())) 20 } 21 if location != nil { 22 ccWrappers = append(ccWrappers, ccWrapper.NewRequestLogger(ui.RequestLoggerFileWriter(location))) 23 } 24 25 authWrapper := ccWrapper.NewUAAAuthentication(nil, config) 26 27 ccWrappers = append(ccWrappers, authWrapper) 28 ccWrappers = append(ccWrappers, ccWrapper.NewRetryRequest(config.RequestRetryCount())) 29 30 ccClient := ccv3.NewClient(ccv3.Config{ 31 AppName: config.BinaryName(), 32 AppVersion: config.BinaryVersion(), 33 JobPollingTimeout: config.OverallPollingTimeout(), 34 JobPollingInterval: config.PollingInterval(), 35 Wrappers: ccWrappers, 36 }) 37 38 if !targetCF { 39 return ccClient, nil, nil 40 } 41 42 if config.Target() == "" { 43 return nil, nil, translatableerror.NoAPISetError{ 44 BinaryName: config.BinaryName(), 45 } 46 } 47 48 _, _, err := ccClient.TargetCF(ccv3.TargetSettings{ 49 URL: config.Target(), 50 SkipSSLValidation: config.SkipSSLValidation(), 51 DialTimeout: config.DialTimeout(), 52 }) 53 if err != nil { 54 return nil, nil, err 55 } 56 57 if ccClient.UAA() == "" { 58 return nil, nil, translatableerror.UAAEndpointNotFoundError{} 59 } 60 61 uaaClient := uaa.NewClient(config) 62 63 if verbose { 64 uaaClient.WrapConnection(uaaWrapper.NewRequestLogger(ui.RequestLoggerTerminalDisplay())) 65 } 66 if location != nil { 67 uaaClient.WrapConnection(uaaWrapper.NewRequestLogger(ui.RequestLoggerFileWriter(location))) 68 } 69 70 uaaAuthWrapper := uaaWrapper.NewUAAAuthentication(uaaClient, config) 71 uaaClient.WrapConnection(uaaAuthWrapper) 72 uaaClient.WrapConnection(uaaWrapper.NewRetryRequest(config.RequestRetryCount())) 73 74 err = uaaClient.SetupResources(ccClient.Login()) 75 if err != nil { 76 return nil, nil, err 77 } 78 79 uaaAuthWrapper.SetClient(uaaClient) 80 authWrapper.SetClient(uaaClient) 81 82 return ccClient, uaaClient, nil 83 }