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 ( ...@@ -32,7 +32,7 @@ require (
github.com/gorilla/websocket v1.4.1 github.com/gorilla/websocket v1.4.1
github.com/gosimple/slug v1.4.2 github.com/gosimple/slug v1.4.2
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 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-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.0.1 github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-version v1.1.0 github.com/hashicorp/go-version v1.1.0
......
...@@ -133,8 +133,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ= ...@@ -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/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 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-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.21.0 h1:5en5MdVFgeD9tuHDuJgwHYdIVjPs0PN0a7ZQ2bZNxNk=
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/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 h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= 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= github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
......
...@@ -277,10 +277,6 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) { ...@@ -277,10 +277,6 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
config := backendplugin.PluginConfig{ config := backendplugin.PluginConfig{
OrgID: c.OrgId, OrgID: c.OrgId,
PluginID: plugin.Id, PluginID: plugin.Id,
PluginType: plugin.Type,
JSONData: ds.JsonData,
DecryptedSecureJSONData: ds.DecryptedValues(),
Updated: ds.Updated,
DataSourceConfig: &backendplugin.DataSourceConfig{ DataSourceConfig: &backendplugin.DataSourceConfig{
ID: ds.Id, ID: ds.Id,
Name: ds.Name, Name: ds.Name,
...@@ -289,6 +285,9 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) { ...@@ -289,6 +285,9 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
User: ds.User, User: ds.User,
BasicAuthEnabled: ds.BasicAuth, BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser, BasicAuthUser: ds.BasicAuthUser,
JSONData: ds.JsonData,
DecryptedSecureJSONData: ds.DecryptedValues(),
Updated: ds.Updated,
}, },
} }
hs.BackendPluginManager.CallResource(config, c, c.Params("*")) hs.BackendPluginManager.CallResource(config, c, c.Params("*"))
......
...@@ -268,7 +268,6 @@ func (hs *HTTPServer) CallResource(c *models.ReqContext) { ...@@ -268,7 +268,6 @@ func (hs *HTTPServer) CallResource(c *models.ReqContext) {
config := backendplugin.PluginConfig{ config := backendplugin.PluginConfig{
OrgID: c.OrgId, OrgID: c.OrgId,
PluginID: plugin.Id, PluginID: plugin.Id,
PluginType: plugin.Type,
JSONData: jsonData, JSONData: jsonData,
DecryptedSecureJSONData: decryptedSecureJSONData, DecryptedSecureJSONData: decryptedSecureJSONData,
Updated: updated, Updated: updated,
......
...@@ -229,10 +229,9 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques ...@@ -229,10 +229,9 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
Config: &pluginv2.PluginConfig{ Config: &pluginv2.PluginConfig{
OrgId: req.Config.OrgID, OrgId: req.Config.OrgID,
PluginId: req.Config.PluginID, PluginId: req.Config.PluginID,
PluginType: req.Config.PluginType,
JsonData: jsonDataBytes, JsonData: jsonDataBytes,
DecryptedSecureJsonData: req.Config.DecryptedSecureJSONData, DecryptedSecureJsonData: req.Config.DecryptedSecureJSONData,
UpdatedMS: req.Config.Updated.UnixNano() / int64(time.Millisecond), LastUpdatedMS: req.Config.Updated.UnixNano() / int64(time.Millisecond),
}, },
Path: req.Path, Path: req.Path,
Method: req.Method, Method: req.Method,
...@@ -251,6 +250,11 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques ...@@ -251,6 +250,11 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
} }
if req.Config.DataSourceConfig != nil { if req.Config.DataSourceConfig != nil {
datasourceJSONData, err := req.Config.DataSourceConfig.JSONData.ToDB()
if err != nil {
return nil, err
}
protoReq.Config.DatasourceConfig = &pluginv2.DataSourceConfig{ protoReq.Config.DatasourceConfig = &pluginv2.DataSourceConfig{
Id: req.Config.DataSourceConfig.ID, Id: req.Config.DataSourceConfig.ID,
Name: req.Config.DataSourceConfig.Name, Name: req.Config.DataSourceConfig.Name,
...@@ -259,6 +263,9 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques ...@@ -259,6 +263,9 @@ func (p *BackendPlugin) callResource(ctx context.Context, req CallResourceReques
User: req.Config.DataSourceConfig.User, User: req.Config.DataSourceConfig.User,
BasicAuthEnabled: req.Config.DataSourceConfig.BasicAuthEnabled, BasicAuthEnabled: req.Config.DataSourceConfig.BasicAuthEnabled,
BasicAuthUser: req.Config.DataSourceConfig.BasicAuthUser, BasicAuthUser: req.Config.DataSourceConfig.BasicAuthUser,
JsonData: datasourceJSONData,
DecryptedSecureJsonData: req.Config.DataSourceConfig.DecryptedSecureJSONData,
LastUpdatedMS: req.Config.DataSourceConfig.Updated.UnixNano() / int64(time.Millisecond),
} }
} }
......
...@@ -67,12 +67,14 @@ type DataSourceConfig struct { ...@@ -67,12 +67,14 @@ type DataSourceConfig struct {
Database string Database string
BasicAuthEnabled bool BasicAuthEnabled bool
BasicAuthUser string BasicAuthUser string
JSONData *simplejson.Json
DecryptedSecureJSONData map[string]string
Updated time.Time
} }
type PluginConfig struct { type PluginConfig struct {
OrgID int64 OrgID int64
PluginID string PluginID string
PluginType string
JSONData *simplejson.Json JSONData *simplejson.Json
DecryptedSecureJSONData map[string]string DecryptedSecureJSONData map[string]string
Updated time.Time Updated time.Time
......
...@@ -34,10 +34,7 @@ func (tw *DatasourcePluginWrapperV2) Query(ctx context.Context, ds *models.DataS ...@@ -34,10 +34,7 @@ func (tw *DatasourcePluginWrapperV2) Query(ctx context.Context, ds *models.DataS
Config: &pluginv2.PluginConfig{ Config: &pluginv2.PluginConfig{
OrgId: ds.OrgId, OrgId: ds.OrgId,
PluginId: tw.pluginId, PluginId: tw.pluginId,
PluginType: tw.pluginType, LastUpdatedMS: ds.Updated.UnixNano() / int64(time.Millisecond),
UpdatedMS: ds.Updated.UnixNano() / int64(time.Millisecond),
JsonData: jsonDataBytes,
DecryptedSecureJsonData: ds.DecryptedValues(),
DatasourceConfig: &pluginv2.DataSourceConfig{ DatasourceConfig: &pluginv2.DataSourceConfig{
Id: ds.Id, Id: ds.Id,
Name: ds.Name, Name: ds.Name,
...@@ -46,6 +43,8 @@ func (tw *DatasourcePluginWrapperV2) Query(ctx context.Context, ds *models.DataS ...@@ -46,6 +43,8 @@ func (tw *DatasourcePluginWrapperV2) Query(ctx context.Context, ds *models.DataS
User: ds.User, User: ds.User,
BasicAuthEnabled: ds.BasicAuth, BasicAuthEnabled: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser, BasicAuthUser: ds.BasicAuthUser,
JsonData: jsonDataBytes,
DecryptedSecureJsonData: ds.DecryptedValues(),
}, },
}, },
Queries: []*pluginv2.DataQuery{}, Queries: []*pluginv2.DataQuery{},
......
...@@ -147,7 +147,7 @@ github.com/gosimple/slug ...@@ -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 v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-model/go/datasource github.com/grafana/grafana-plugin-model/go/datasource
github.com/grafana/grafana-plugin-model/go/renderer 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/backend/plugin
github.com/grafana/grafana-plugin-sdk-go/dataframe github.com/grafana/grafana-plugin-sdk-go/dataframe
github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2 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