MCPcopy
hub / github.com/cloudfoundry/cli / NewClient

Function NewClient

api/logcache/log_cache_client.go:109–155  ·  view source on GitHub ↗

NewClient returns back a configured Log Cache Client.

(logCacheEndpoint string, config command.Config, ui command.UI, k8sConfigGetter v7action.KubernetesConfigGetter)

Source from the content-addressed store, hash-verified

107
108// NewClient returns back a configured Log Cache Client.
109func 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
157func headersString(header http.Header) string {
158 var result string

Callers 8

SetupMethod · 0.92
SetupMethod · 0.92
SetupMethod · 0.92
SetupMethod · 0.92
SetupMethod · 0.92
SetupMethod · 0.92
SetupMethod · 0.92
NewRepositoryLocatorFunction · 0.92

Calls 12

addOutputMethod · 0.95
NewTLSConfigFunction · 0.92
WrapForCFOnK8sAuthFunction · 0.92
VersionMethod · 0.80
SkipSSLValidationMethod · 0.65
DialTimeoutMethod · 0.65
IsCFOnK8sMethod · 0.65
BinaryNameMethod · 0.65
BinaryVersionMethod · 0.65
VerboseMethod · 0.65

Tested by

no test coverage detected