Datasource API: Add config to ctx (#83386)

This commit is contained in:
Andres Martinez Gotor 2024-02-26 13:02:55 +01:00 committed by GitHub
parent 5756f365e3
commit fc8a9aad22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View File

@ -36,7 +36,7 @@ type DataSourceAPIBuilder struct {
connectionResourceInfo common.ResourceInfo
pluginJSON plugins.JSONData
client plugins.Client // will only ever be called with the same pluginid!
client PluginClient // will only ever be called with the same pluginid!
datasources PluginDatasourceProvider
contextProvider PluginContextWrapper
accessControl accesscontrol.AccessControl
@ -82,9 +82,17 @@ func RegisterAPIService(
return builder, nil // only used for wire
}
// PluginClient is a subset of the plugins.Client interface with only the
// functions supported (yet) by the datasource API
type PluginClient interface {
backend.QueryDataHandler
backend.CheckHealthHandler
backend.CallResourceHandler
}
func NewDataSourceAPIBuilder(
plugin plugins.JSONData,
client plugins.Client,
client PluginClient,
datasources PluginDatasourceProvider,
contextProvider PluginContextWrapper,
accessControl accesscontrol.AccessControl) (*DataSourceAPIBuilder, error) {

View File

@ -40,6 +40,7 @@ func (r *subHealthREST) Connect(ctx context.Context, name string, opts runtime.O
responder.Error(err)
return
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
healthResponse, err := r.builder.client.CheckHealth(ctx, &backend.CheckHealthRequest{
PluginContext: pluginCtx,

View File

@ -77,6 +77,7 @@ func (r *subQueryREST) Connect(ctx context.Context, name string, opts runtime.Ob
if err != nil {
return nil, err
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
queries, dsRef, err := r.readQueries(req)

View File

@ -50,6 +50,7 @@ func (r *subResourceREST) Connect(ctx context.Context, name string, opts runtime
if err != nil {
return nil, err
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(req.Body)