NewClient returns back a configured Log Cache Client.
(logCacheEndpoint string, config command.Config, ui command.UI, k8sConfigGetter v7action.KubernetesConfigGetter)
| 107 | |
| 108 | // NewClient returns back a configured Log Cache Client. |
| 109 | func NewClient(logCacheEndpoint string, config command.Config, ui command.UI, k8sConfigGetter v7action.KubernetesConfigGetter) (*logcache.Client, error) { |
| 110 | var tr http.RoundTripper = &http.Transport{ |
| 111 | Proxy: http.ProxyFromEnvironment, |
| 112 | TLSClientConfig: util.NewTLSConfig(nil, config.SkipSSLValidation()), |
| 113 | DialContext: (&net.Dialer{ |
| 114 | KeepAlive: 30 * time.Second, |
| 115 | Timeout: config.DialTimeout(), |
| 116 | }).DialContext, |
| 117 | } |
| 118 | |
| 119 | if config.IsCFOnK8s() { |
| 120 | var err error |
| 121 | tr, err = shared.WrapForCFOnK8sAuth(config, k8sConfigGetter, tr) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | var client logcache.HTTPClient // nolint |
| 128 | client = &userAgentHTTPClient{ |
| 129 | c: &http.Client{Transport: tr}, |
| 130 | userAgent: fmt.Sprintf("%s/%s (%s; %s %s)", config.BinaryName(), config.BinaryVersion(), runtime.Version(), runtime.GOARCH, runtime.GOOS), |
| 131 | } |
| 132 | |
| 133 | verbose, location := config.Verbose() |
| 134 | if verbose && ui != nil { |
| 135 | printer := DebugPrinter{} |
| 136 | printer.addOutput(ui.RequestLoggerTerminalDisplay()) |
| 137 | if location != nil { |
| 138 | printer.addOutput(ui.RequestLoggerFileWriter(location)) |
| 139 | } |
| 140 | |
| 141 | client = &httpDebugClient{printer: printer, c: client} |
| 142 | } |
| 143 | |
| 144 | if !config.IsCFOnK8s() { |
| 145 | client = &tokenHTTPClient{ |
| 146 | c: client, |
| 147 | accessToken: config.AccessToken, |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return logcache.NewClient( |
| 152 | logCacheEndpoint, |
| 153 | logcache.WithHTTPClient(client), |
| 154 | ), nil |
| 155 | } |
| 156 | |
| 157 | func headersString(header http.Header) string { |
| 158 | var result string |
no test coverage detected