in pkg/api/api.go [42:93]
func NewAPI(c Config) (*API, error) {
c.fillDefaults()
if err := c.Validate(); err != nil {
return nil, err
}
t, err := NewTransport(c.Client.Transport, TransportConfig{
SkipTLSVerify: c.SkipTLSVerify,
ErrorDevice: c.ErrorDevice,
VerboseSettings: c.VerboseSettings,
Timeout: c.Timeout,
UserAgent: c.UserAgent,
Retries: c.Retries,
RetryBackoff: c.RetryBackoff,
})
if err != nil {
return nil, err
}
c.Client.Transport = t
// Sadly, all the client parameters take the DefaultTimeout from the runtime
// client if not specified in the call as a query parameter, modifying this
// value effectively affects all of the related clients.
runtimeclient.DefaultTimeout = c.Timeout
// If retries are set, then we don't want the framework cancellation to kick in
// while we're still retrying requests, to enable that, we're multiplying the
// specified timeout by the # of retries, accounting for the backoffs as well.
if c.Retries > 0 {
if c.RetryBackoff.Microseconds() <= 0 {
c.RetryBackoff = defaultBackoff
}
runtimeclient.DefaultTimeout = c.Timeout*time.Duration(c.Retries) + (c.RetryBackoff * time.Duration(c.Retries))
// We leave the http client with no timeout, since we don't want yet another
// layer of context cancellatins to step in.
c.Client.Timeout = 0
}
transport, err := NewCloudClientRuntime(c)
if err != nil {
return nil, err
}
var api = API{AuthWriter: c.AuthWriter, V1API: client.New(transport, nil)}
if !c.SkipLogin {
if err := LoginUser(&api, c.ErrorDevice); err != nil {
return nil, err
}
}
return &api, nil
}