diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 7dd28a533e5..2a90a6f04a2 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -13,25 +13,13 @@ import ( "strings" "sync" - "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/middleware/csrf" - "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/authn" - "github.com/grafana/grafana/pkg/services/folder" - "github.com/grafana/grafana/pkg/services/licensing" - "github.com/grafana/grafana/pkg/services/oauthtoken" - "github.com/grafana/grafana/pkg/services/querylibrary" - "github.com/grafana/grafana/pkg/services/searchV2" - "github.com/grafana/grafana/pkg/services/stats" - "github.com/grafana/grafana/pkg/services/store/entity/httpentitystore" - "github.com/grafana/grafana/pkg/services/store/k8saccess" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/grafana/grafana/pkg/api/avatar" "github.com/grafana/grafana/pkg/api/routing" httpstatic "github.com/grafana/grafana/pkg/api/static" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/kvstore" @@ -42,7 +30,7 @@ import ( loginpkg "github.com/grafana/grafana/pkg/login" "github.com/grafana/grafana/pkg/login/social" "github.com/grafana/grafana/pkg/middleware" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/middleware/csrf" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins/plugincontext" "github.com/grafana/grafana/pkg/registry/corekind" @@ -50,6 +38,8 @@ import ( "github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/apikey" + "github.com/grafana/grafana/pkg/services/auth" + "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/cleanup" "github.com/grafana/grafana/pkg/services/comments" "github.com/grafana/grafana/pkg/services/contexthandler" @@ -63,10 +53,12 @@ import ( "github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/export" "github.com/grafana/grafana/pkg/services/featuremgmt" + "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/hooks" "github.com/grafana/grafana/pkg/services/ldap" "github.com/grafana/grafana/pkg/services/libraryelements" "github.com/grafana/grafana/pkg/services/librarypanels" + "github.com/grafana/grafana/pkg/services/licensing" "github.com/grafana/grafana/pkg/services/live" "github.com/grafana/grafana/pkg/services/live/pushhttp" "github.com/grafana/grafana/pkg/services/login" @@ -74,6 +66,7 @@ import ( "github.com/grafana/grafana/pkg/services/navtree" "github.com/grafana/grafana/pkg/services/ngalert" "github.com/grafana/grafana/pkg/services/notifications" + "github.com/grafana/grafana/pkg/services/oauthtoken" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/playlist" "github.com/grafana/grafana/pkg/services/plugindashboards" @@ -83,9 +76,11 @@ import ( publicdashboardsApi "github.com/grafana/grafana/pkg/services/publicdashboards/api" "github.com/grafana/grafana/pkg/services/query" "github.com/grafana/grafana/pkg/services/queryhistory" + "github.com/grafana/grafana/pkg/services/querylibrary" "github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/services/search" + "github.com/grafana/grafana/pkg/services/searchV2" "github.com/grafana/grafana/pkg/services/searchusers" "github.com/grafana/grafana/pkg/services/secrets" secretsKV "github.com/grafana/grafana/pkg/services/secrets/kvstore" @@ -94,7 +89,10 @@ import ( "github.com/grafana/grafana/pkg/services/shorturls" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/star" + "github.com/grafana/grafana/pkg/services/stats" "github.com/grafana/grafana/pkg/services/store" + "github.com/grafana/grafana/pkg/services/store/entity/httpentitystore" + "github.com/grafana/grafana/pkg/services/store/k8saccess" "github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/team" "github.com/grafana/grafana/pkg/services/teamguardian" @@ -102,6 +100,7 @@ import ( "github.com/grafana/grafana/pkg/services/thumbs" "github.com/grafana/grafana/pkg/services/updatechecker" "github.com/grafana/grafana/pkg/services/user" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/web" ) @@ -133,7 +132,7 @@ type HTTPServer struct { License licensing.Licensing AccessControl accesscontrol.AccessControl DataProxy *datasourceproxy.DataSourceProxyService - PluginRequestValidator models.PluginRequestValidator + PluginRequestValidator validations.PluginRequestValidator pluginClient plugins.Client pluginStore plugins.Store pluginInstaller plugins.Installer @@ -223,7 +222,7 @@ type ServerOptions struct { func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus, renderService rendering.Service, licensing licensing.Licensing, hooksService *hooks.HooksService, cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore, alertEngine *alerting.AlertEngine, - pluginRequestValidator models.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver, + pluginRequestValidator validations.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver, pluginDashboardService plugindashboards.Service, pluginStore plugins.Store, pluginClient plugins.Client, pluginErrorResolver plugins.ErrorResolver, pluginInstaller plugins.Installer, settingsProvider setting.Provider, dataSourceCache datasources.CacheService, userTokenService auth.UserTokenService, diff --git a/pkg/cmd/grafana-cli/runner/wireexts_oss.go b/pkg/cmd/grafana-cli/runner/wireexts_oss.go index 313cafad088..be33d32cd94 100644 --- a/pkg/cmd/grafana-cli/runner/wireexts_oss.go +++ b/pkg/cmd/grafana-cli/runner/wireexts_oss.go @@ -6,7 +6,6 @@ package runner import ( "github.com/google/wire" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/registry" "github.com/grafana/grafana/pkg/server/backgroundsvcs" "github.com/grafana/grafana/pkg/server/usagestatssvcs" @@ -56,7 +55,7 @@ var wireExtsSet = wire.NewSet( thumbs.ProvideCrawlerAuthSetupService, wire.Bind(new(thumbs.CrawlerAuthSetupService), new(*thumbs.OSSCrawlerAuthSetupService)), validations.ProvideValidator, - wire.Bind(new(models.PluginRequestValidator), new(*validations.OSSPluginRequestValidator)), + wire.Bind(new(validations.PluginRequestValidator), new(*validations.OSSPluginRequestValidator)), provisioning.ProvideService, wire.Bind(new(provisioning.ProvisioningService), new(*provisioning.ProvisioningServiceImpl)), backgroundsvcs.ProvideBackgroundServiceRegistry, diff --git a/pkg/infra/httpclient/httpclientprovider/host_redirect_validation_middleware.go b/pkg/infra/httpclient/httpclientprovider/host_redirect_validation_middleware.go index 7bffa1126c6..c53ead6e7a5 100644 --- a/pkg/infra/httpclient/httpclientprovider/host_redirect_validation_middleware.go +++ b/pkg/infra/httpclient/httpclientprovider/host_redirect_validation_middleware.go @@ -4,14 +4,14 @@ import ( "errors" "net/http" - "github.com/grafana/grafana/pkg/models" - sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" + + "github.com/grafana/grafana/pkg/services/validations" ) const HostRedirectValidationMiddlewareName = "host-redirect-validation" -func RedirectLimitMiddleware(reqValidator models.PluginRequestValidator) sdkhttpclient.Middleware { +func RedirectLimitMiddleware(reqValidator validations.PluginRequestValidator) sdkhttpclient.Middleware { return sdkhttpclient.NamedMiddlewareFunc(HostRedirectValidationMiddlewareName, func(opts sdkhttpclient.Options, next http.RoundTripper) http.RoundTripper { return sdkhttpclient.RoundTripperFunc(func(req *http.Request) (*http.Response, error) { res, err := next.RoundTrip(req) diff --git a/pkg/infra/httpclient/httpclientprovider/http_client_provider.go b/pkg/infra/httpclient/httpclientprovider/http_client_provider.go index da9eb67f966..c8aea67c8a3 100644 --- a/pkg/infra/httpclient/httpclientprovider/http_client_provider.go +++ b/pkg/infra/httpclient/httpclientprovider/http_client_provider.go @@ -6,19 +6,20 @@ import ( "time" sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" + "github.com/mwitkow/go-conntrack" + "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics/metricutil" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/featuremgmt" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" - "github.com/mwitkow/go-conntrack" ) var newProviderFunc = sdkhttpclient.NewProvider // New creates a new HTTP client provider with pre-configured middlewares. -func New(cfg *setting.Cfg, validator models.PluginRequestValidator, tracer tracing.Tracer) *sdkhttpclient.Provider { +func New(cfg *setting.Cfg, validator validations.PluginRequestValidator, tracer tracing.Tracer) *sdkhttpclient.Provider { logger := log.New("httpclient") userAgent := fmt.Sprintf("Grafana/%s", cfg.BuildVersion) diff --git a/pkg/server/wireexts_oss.go b/pkg/server/wireexts_oss.go index a8ea8aa44de..6ce8a35c7f4 100644 --- a/pkg/server/wireexts_oss.go +++ b/pkg/server/wireexts_oss.go @@ -6,7 +6,6 @@ package server import ( "github.com/google/wire" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/registry" "github.com/grafana/grafana/pkg/server/backgroundsvcs" @@ -53,7 +52,7 @@ var wireExtsBasicSet = wire.NewSet( thumbs.ProvideCrawlerAuthSetupService, wire.Bind(new(thumbs.CrawlerAuthSetupService), new(*thumbs.OSSCrawlerAuthSetupService)), validations.ProvideValidator, - wire.Bind(new(models.PluginRequestValidator), new(*validations.OSSPluginRequestValidator)), + wire.Bind(new(validations.PluginRequestValidator), new(*validations.OSSPluginRequestValidator)), provisioning.ProvideService, wire.Bind(new(provisioning.ProvisioningService), new(*provisioning.ProvisioningServiceImpl)), backgroundsvcs.ProvideBackgroundServiceRegistry, diff --git a/pkg/services/alerting/engine.go b/pkg/services/alerting/engine.go index 316b3771305..c20c821bb0d 100644 --- a/pkg/services/alerting/engine.go +++ b/pkg/services/alerting/engine.go @@ -15,13 +15,13 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/infra/usagestats" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/rendering" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/legacydata" "github.com/grafana/grafana/pkg/util/ticker" @@ -32,7 +32,7 @@ import ( // are sent. type AlertEngine struct { RenderService rendering.Service - RequestValidator models.PluginRequestValidator + RequestValidator validations.PluginRequestValidator DataService legacydata.RequestHandler Cfg *setting.Cfg @@ -58,7 +58,7 @@ func (e *AlertEngine) IsDisabled() bool { } // ProvideAlertEngine returns a new AlertEngine. -func ProvideAlertEngine(renderer rendering.Service, requestValidator models.PluginRequestValidator, +func ProvideAlertEngine(renderer rendering.Service, requestValidator validations.PluginRequestValidator, dataService legacydata.RequestHandler, usageStatsService usagestats.Service, encryptionService encryption.Internal, notificationService *notifications.NotificationService, tracer tracing.Tracer, store AlertStore, cfg *setting.Cfg, dashAlertExtractor DashAlertExtractor, dashboardService dashboards.DashboardService, cacheService *localcache.CacheService, dsService datasources.DataSourceService, annotationsRepo annotations.Repository) *AlertEngine { diff --git a/pkg/services/alerting/eval_context.go b/pkg/services/alerting/eval_context.go index dff04f79e59..d5375cae94d 100644 --- a/pkg/services/alerting/eval_context.go +++ b/pkg/services/alerting/eval_context.go @@ -7,11 +7,11 @@ import ( "time" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models" alertmodels "github.com/grafana/grafana/pkg/services/alerting/models" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" ) @@ -37,7 +37,7 @@ type EvalContext struct { NoDataFound bool PrevAlertState alertmodels.AlertStateType - RequestValidator models.PluginRequestValidator + RequestValidator validations.PluginRequestValidator Ctx context.Context @@ -48,7 +48,7 @@ type EvalContext struct { } // NewEvalContext is the EvalContext constructor. -func NewEvalContext(alertCtx context.Context, rule *Rule, requestValidator models.PluginRequestValidator, +func NewEvalContext(alertCtx context.Context, rule *Rule, requestValidator validations.PluginRequestValidator, alertStore AlertStore, dashboardService dashboards.DashboardService, dsService datasources.DataSourceService, annotationRepo annotations.Repository) *EvalContext { return &EvalContext{ Ctx: alertCtx, diff --git a/pkg/services/datasourceproxy/datasourceproxy.go b/pkg/services/datasourceproxy/datasourceproxy.go index 0590376c741..81a2f5fdb1c 100644 --- a/pkg/services/datasourceproxy/datasourceproxy.go +++ b/pkg/services/datasourceproxy/datasourceproxy.go @@ -17,12 +17,13 @@ import ( "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/oauthtoken" "github.com/grafana/grafana/pkg/services/secrets" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/web" ) -func ProvideService(dataSourceCache datasources.CacheService, plugReqValidator models.PluginRequestValidator, +func ProvideService(dataSourceCache datasources.CacheService, plugReqValidator validations.PluginRequestValidator, pluginStore plugins.Store, cfg *setting.Cfg, httpClientProvider httpclient.Provider, oauthTokenService *oauthtoken.Service, dsService datasources.DataSourceService, tracer tracing.Tracer, secretsService secrets.Service) *DataSourceProxyService { @@ -41,7 +42,7 @@ func ProvideService(dataSourceCache datasources.CacheService, plugReqValidator m type DataSourceProxyService struct { DataSourceCache datasources.CacheService - PluginRequestValidator models.PluginRequestValidator + PluginRequestValidator validations.PluginRequestValidator pluginStore plugins.Store Cfg *setting.Cfg HTTPClientProvider httpclient.Provider diff --git a/pkg/services/query/query.go b/pkg/services/query/query.go index 2c0f730c0a9..9befc139afb 100644 --- a/pkg/services/query/query.go +++ b/pkg/services/query/query.go @@ -6,20 +6,21 @@ import ( "time" "github.com/grafana/grafana-plugin-sdk-go/backend" + "golang.org/x/sync/errgroup" + "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins/adapters" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/user" + "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/grafanads" "github.com/grafana/grafana/pkg/tsdb/legacydata" "github.com/grafana/grafana/pkg/util/errutil" - "golang.org/x/sync/errgroup" ) const ( @@ -33,7 +34,7 @@ func ProvideService( cfg *setting.Cfg, dataSourceCache datasources.CacheService, expressionService *expr.Service, - pluginRequestValidator models.PluginRequestValidator, + pluginRequestValidator validations.PluginRequestValidator, dataSourceService datasources.DataSourceService, pluginClient plugins.Client, ) *Service { @@ -54,7 +55,7 @@ type Service struct { cfg *setting.Cfg dataSourceCache datasources.CacheService expressionService *expr.Service - pluginRequestValidator models.PluginRequestValidator + pluginRequestValidator validations.PluginRequestValidator dataSourceService datasources.DataSourceService pluginClient plugins.Client log log.Logger diff --git a/pkg/models/validations.go b/pkg/services/validations/service.go similarity index 92% rename from pkg/models/validations.go rename to pkg/services/validations/service.go index 389e5466f80..9b0d48a8f3d 100644 --- a/pkg/models/validations.go +++ b/pkg/services/validations/service.go @@ -1,4 +1,4 @@ -package models +package validations import ( "net/http"