backend/datasources: move datasources models into the datasources service package (#51267)

* backend/datasources: move datasources models into the datasources service pkg
This commit is contained in:
Kristin Laemmert
2022-06-27 12:23:15 -04:00
committed by GitHub
parent 78c012df65
commit 945f015770
77 changed files with 728 additions and 660 deletions
+8 -7
View File
@@ -11,6 +11,8 @@ import (
"strings"
"time"
"go.opentelemetry.io/otel/attribute"
"github.com/grafana/grafana/pkg/api/datasource"
"github.com/grafana/grafana/pkg/infra/httpclient"
glog "github.com/grafana/grafana/pkg/infra/log"
@@ -22,7 +24,6 @@ import (
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util/proxyutil"
"go.opentelemetry.io/otel/attribute"
)
var (
@@ -31,7 +32,7 @@ var (
)
type DataSourceProxy struct {
ds *models.DataSource
ds *datasources.DataSource
ctx *models.ReqContext
targetUrl *url.URL
proxyPath string
@@ -49,7 +50,7 @@ type httpClient interface {
}
// NewDataSourceProxy creates a new Datasource proxy
func NewDataSourceProxy(ds *models.DataSource, pluginRoutes []*plugins.Route, ctx *models.ReqContext,
func NewDataSourceProxy(ds *datasources.DataSource, pluginRoutes []*plugins.Route, ctx *models.ReqContext,
proxyPath string, cfg *setting.Cfg, clientProvider httpclient.Provider,
oAuthTokenService oauthtoken.OAuthTokenService, dsService datasources.DataSourceService,
tracer tracing.Tracer) (*DataSourceProxy, error) {
@@ -167,7 +168,7 @@ func (proxy *DataSourceProxy) director(req *http.Request) {
reqQueryVals := req.URL.Query()
switch proxy.ds.Type {
case models.DS_INFLUXDB_08:
case datasources.DS_INFLUXDB_08:
password, err := proxy.dataSourcesService.DecryptedPassword(req.Context(), proxy.ds)
if err != nil {
logger.Error("Error interpolating proxy url", "error", err)
@@ -178,7 +179,7 @@ func (proxy *DataSourceProxy) director(req *http.Request) {
reqQueryVals.Add("u", proxy.ds.User)
reqQueryVals.Add("p", password)
req.URL.RawQuery = reqQueryVals.Encode()
case models.DS_INFLUXDB:
case datasources.DS_INFLUXDB:
password, err := proxy.dataSourcesService.DecryptedPassword(req.Context(), proxy.ds)
if err != nil {
logger.Error("Error interpolating proxy url", "error", err)
@@ -266,7 +267,7 @@ func (proxy *DataSourceProxy) validateRequest() error {
return errors.New("target URL is not a valid target")
}
if proxy.ds.Type == models.DS_ES {
if proxy.ds.Type == datasources.DS_ES {
if proxy.ctx.Req.Method == "DELETE" {
return errors.New("deletes not allowed on proxied Elasticsearch datasource")
}
@@ -301,7 +302,7 @@ func (proxy *DataSourceProxy) validateRequest() error {
}
// Trailing validation below this point for routes that were not matched
if proxy.ds.Type == models.DS_PROMETHEUS {
if proxy.ds.Type == datasources.DS_PROMETHEUS {
if proxy.ctx.Req.Method == "DELETE" {
return errors.New("non allow-listed DELETEs not allowed on proxied Prometheus datasource")
}