github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/command/v7/shared/noaa_client.go (about)

     1  package shared
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/uaa"
     7  	"code.cloudfoundry.org/cli/api/uaa/noaabridge"
     8  	"code.cloudfoundry.org/cli/command"
     9  	"code.cloudfoundry.org/cli/util"
    10  	"github.com/cloudfoundry/noaa/consumer"
    11  )
    12  
    13  // NewNOAAClient returns back a configured NOAA Client.
    14  func NewNOAAClient(apiURL string, config command.Config, uaaClient *uaa.Client, ui command.UI) *consumer.Consumer {
    15  	client := consumer.New(
    16  		apiURL,
    17  		util.NewTLSConfig(nil, config.SkipSSLValidation()),
    18  		http.ProxyFromEnvironment,
    19  	)
    20  	client.RefreshTokenFrom(noaabridge.NewTokenRefresher(uaaClient, config))
    21  	client.SetMaxRetryCount(config.NOAARequestRetryCount())
    22  
    23  	noaaDebugPrinter := NOAADebugPrinter{}
    24  
    25  	// if verbose, set debug printer on noaa client
    26  	verbose, location := config.Verbose()
    27  
    28  	client.SetDebugPrinter(&noaaDebugPrinter)
    29  
    30  	if verbose {
    31  		noaaDebugPrinter.addOutput(ui.RequestLoggerTerminalDisplay())
    32  	}
    33  	if location != nil {
    34  		noaaDebugPrinter.addOutput(ui.RequestLoggerFileWriter(location))
    35  	}
    36  
    37  	return client
    38  }