Datasource: Shared HTTP client provider for core backend data sources and any data source using the data source proxy (#33439)
Uses new httpclient package from grafana-plugin-sdk-go introduced via grafana/grafana-plugin-sdk-go#328. Replaces the GetHTTPClient, GetTransport, GetTLSConfig methods defined on DataSource model. Longer-term the goal is to migrate core HTTP backend data sources to use the SDK contracts and using httpclient.Provider for creating HTTP clients and such. Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
co-authored by
Arve Knudsen
parent
7a83d1f9ff
commit
348e76fc8e
@@ -0,0 +1,32 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
)
|
||||
|
||||
// Provider provides abilities to create http.Client, http.RoundTripper and tls.Config.
|
||||
type Provider interface {
|
||||
// New creates a new http.Client given provided options.
|
||||
New(opts ...httpclient.Options) (*http.Client, error)
|
||||
|
||||
// GetTransport creates a new http.RoundTripper given provided options.
|
||||
GetTransport(opts ...httpclient.Options) (http.RoundTripper, error)
|
||||
|
||||
// GetTLSConfig creates a new tls.Config given provided options.
|
||||
GetTLSConfig(opts ...httpclient.Options) (*tls.Config, error)
|
||||
}
|
||||
|
||||
// NewProvider creates a new HTTP client provider.
|
||||
// Optionally provide ProviderOptions options that will be used as default if
|
||||
// not specified in Options argument to Provider.New, Provider.GetTransport and
|
||||
// Provider.GetTLSConfig.
|
||||
// If no middlewares are provided in opts the DefaultMiddlewares() will be used. If you
|
||||
// provide middlewares you have to manually add the DefaultMiddlewares() for it to be
|
||||
// enabled.
|
||||
// Note: Middlewares will be executed in the same order as provided.
|
||||
func NewProvider(opts ...httpclient.ProviderOptions) *httpclient.Provider {
|
||||
return httpclient.NewProvider(opts...)
|
||||
}
|
||||
Reference in New Issue
Block a user