mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 18:52:34 +08:00
Backend Plugins: Provide proper plugin config to plugins (#21985)
Properly provides plugin configs to backend plugins. Uses v0.16.0 of grafana-plugin-sdk-go- Ref #21512 Ref #19667
This commit is contained in:

committed by
GitHub

parent
f82a6aa0d0
commit
9d7c74ef91
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@ -205,13 +206,33 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
|
||||
}
|
||||
|
||||
protoReq := &pluginv2.CallResource_Request{
|
||||
Config: &pluginv2.PluginConfig{},
|
||||
Config: &pluginv2.PluginConfig{
|
||||
OrgId: req.Config.OrgID,
|
||||
PluginId: req.Config.PluginID,
|
||||
PluginType: req.Config.PluginType,
|
||||
JsonData: req.Config.JSONData,
|
||||
DecryptedSecureJsonData: req.Config.DecryptedSecureJSONData,
|
||||
UpdatedMS: req.Config.Updated.UnixNano() / int64(time.Millisecond),
|
||||
},
|
||||
Path: req.Path,
|
||||
Method: req.Method,
|
||||
Url: req.URL,
|
||||
Headers: reqHeaders,
|
||||
Body: req.Body,
|
||||
}
|
||||
|
||||
if req.Config.DataSourceConfig != nil {
|
||||
protoReq.Config.DatasourceConfig = &pluginv2.DataSourceConfig{
|
||||
Id: req.Config.DataSourceConfig.ID,
|
||||
Name: req.Config.DataSourceConfig.Name,
|
||||
Url: req.Config.DataSourceConfig.URL,
|
||||
Database: req.Config.DataSourceConfig.Database,
|
||||
User: req.Config.DataSourceConfig.User,
|
||||
BasicAuthEnabled: req.Config.DataSourceConfig.BasicAuthEnabled,
|
||||
BasicAuthUser: req.Config.DataSourceConfig.BasicAuthUser,
|
||||
}
|
||||
}
|
||||
|
||||
protoResp, err := p.core.CallResource(ctx, protoReq)
|
||||
if err != nil {
|
||||
if st, ok := status.FromError(err); ok {
|
||||
|
@ -3,6 +3,7 @@ package backendplugin
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2"
|
||||
)
|
||||
@ -54,18 +55,24 @@ func checkHealthResultFromProto(protoResp *pluginv2.CheckHealth_Response) *Check
|
||||
}
|
||||
}
|
||||
|
||||
type PluginInstance struct {
|
||||
ID int64
|
||||
Name string
|
||||
Type string
|
||||
URL string
|
||||
JSONData json.RawMessage
|
||||
type DataSourceConfig struct {
|
||||
ID int64
|
||||
Name string
|
||||
URL string
|
||||
User string
|
||||
Database string
|
||||
BasicAuthEnabled bool
|
||||
BasicAuthUser string
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
PluginID string
|
||||
OrgID int64
|
||||
Instance *PluginInstance
|
||||
OrgID int64
|
||||
PluginID string
|
||||
PluginType string
|
||||
JSONData json.RawMessage
|
||||
DecryptedSecureJSONData map[string]string
|
||||
Updated time.Time
|
||||
DataSourceConfig *DataSourceConfig
|
||||
}
|
||||
|
||||
type CallResourceRequest struct {
|
||||
|
Reference in New Issue
Block a user