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