Commit 5f94d31d by Carl Bergquist Committed by GitHub

Send jsondata for Datasources on DatasourceConfig for backend plugins (#22681)

ref https://github.com/grafana/grafana-plugin-sdk-go/pull/84
parent 62c824e3
......@@ -32,7 +32,7 @@ require (
github.com/gorilla/websocket v1.4.1
github.com/gosimple/slug v1.4.2
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-sdk-go v0.20.0
github.com/grafana/grafana-plugin-sdk-go v0.21.0
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-version v1.1.0
......
......@@ -133,8 +133,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ=
github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 h1:SPdxCL9BChFTlyi0Khv64vdCW4TMna8+sxL7+Chx+Ag=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To=
github.com/grafana/grafana-plugin-sdk-go v0.20.0 h1:01Hit/9HNxyvUcfECvnFSB8LIrbsYSlHvyPvKKczuPo=
github.com/grafana/grafana-plugin-sdk-go v0.20.0/go.mod h1:G6Ov9M+FDOZXNw8eKXINO6XzqdUvTs7huwyQp5jLTBQ=
github.com/grafana/grafana-plugin-sdk-go v0.21.0 h1:5en5MdVFgeD9tuHDuJgwHYdIVjPs0PN0a7ZQ2bZNxNk=
github.com/grafana/grafana-plugin-sdk-go v0.21.0/go.mod h1:G6Ov9M+FDOZXNw8eKXINO6XzqdUvTs7huwyQp5jLTBQ=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
......
......@@ -275,20 +275,19 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
}
config := backendplugin.PluginConfig{
OrgID: c.OrgId,
PluginID: plugin.Id,
PluginType: plugin.Type,
JSONData: ds.JsonData,
DecryptedSecureJSONData: ds.DecryptedValues(),
Updated: ds.Updated,
OrgID: c.OrgId,
PluginID: plugin.Id,
DataSourceConfig: &backendplugin.DataSourceConfig{
ID: ds.Id,
Name: ds.Name,
URL: ds.Url,
Database: ds.Database,
User: ds.User,
BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser,
ID: ds.Id,
Name: ds.Name,
URL: ds.Url,
Database: ds.Database,
User: ds.User,
BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser,
JSONData: ds.JsonData,
DecryptedSecureJSONData: ds.DecryptedValues(),
Updated: ds.Updated,
},
}
hs.BackendPluginManager.CallResource(config, c, c.Params("*"))
......
......@@ -268,7 +268,6 @@ func (hs *HTTPServer) CallResource(c *models.ReqContext) {
config := backendplugin.PluginConfig{
OrgID: c.OrgId,
PluginID: plugin.Id,
PluginType: plugin.Type,
JSONData: jsonData,
DecryptedSecureJSONData: decryptedSecureJSONData,
Updated: updated,
......
......@@ -229,10 +229,9 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
Config: &pluginv2.PluginConfig{
OrgId: req.Config.OrgID,
PluginId: req.Config.PluginID,
PluginType: req.Config.PluginType,
JsonData: jsonDataBytes,
DecryptedSecureJsonData: req.Config.DecryptedSecureJSONData,
UpdatedMS: req.Config.Updated.UnixNano() / int64(time.Millisecond),
LastUpdatedMS: req.Config.Updated.UnixNano() / int64(time.Millisecond),
},
Path: req.Path,
Method: req.Method,
......@@ -251,14 +250,22 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
}
if req.Config.DataSourceConfig != nil {
datasourceJSONData, err := req.Config.DataSourceConfig.JSONData.ToDB()
if err != nil {
return nil, err
}
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,
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,
JsonData: datasourceJSONData,
DecryptedSecureJsonData: req.Config.DataSourceConfig.DecryptedSecureJSONData,
LastUpdatedMS: req.Config.DataSourceConfig.Updated.UnixNano() / int64(time.Millisecond),
}
}
......
......@@ -60,19 +60,21 @@ func checkHealthResultFromProto(protoResp *pluginv2.CheckHealthResponse) *CheckH
}
type DataSourceConfig struct {
ID int64
Name string
URL string
User string
Database string
BasicAuthEnabled bool
BasicAuthUser string
ID int64
Name string
URL string
User string
Database string
BasicAuthEnabled bool
BasicAuthUser string
JSONData *simplejson.Json
DecryptedSecureJSONData map[string]string
Updated time.Time
}
type PluginConfig struct {
OrgID int64
PluginID string
PluginType string
JSONData *simplejson.Json
DecryptedSecureJSONData map[string]string
Updated time.Time
......
......@@ -32,20 +32,19 @@ func (tw *DatasourcePluginWrapperV2) Query(ctx context.Context, ds *models.DataS
pbQuery := &pluginv2.QueryDataRequest{
Config: &pluginv2.PluginConfig{
OrgId: ds.OrgId,
PluginId: tw.pluginId,
PluginType: tw.pluginType,
UpdatedMS: ds.Updated.UnixNano() / int64(time.Millisecond),
JsonData: jsonDataBytes,
DecryptedSecureJsonData: ds.DecryptedValues(),
OrgId: ds.OrgId,
PluginId: tw.pluginId,
LastUpdatedMS: ds.Updated.UnixNano() / int64(time.Millisecond),
DatasourceConfig: &pluginv2.DataSourceConfig{
Id: ds.Id,
Name: ds.Name,
Url: ds.Url,
Database: ds.Database,
User: ds.User,
BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser,
Id: ds.Id,
Name: ds.Name,
Url: ds.Url,
Database: ds.Database,
User: ds.User,
BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser,
JsonData: jsonDataBytes,
DecryptedSecureJsonData: ds.DecryptedValues(),
},
},
Queries: []*pluginv2.DataQuery{},
......
......@@ -147,7 +147,7 @@ github.com/gosimple/slug
# github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-model/go/datasource
github.com/grafana/grafana-plugin-model/go/renderer
# github.com/grafana/grafana-plugin-sdk-go v0.20.0
# github.com/grafana/grafana-plugin-sdk-go v0.21.0
github.com/grafana/grafana-plugin-sdk-go/backend/plugin
github.com/grafana/grafana-plugin-sdk-go/dataframe
github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment