diff --git a/pkg/cmd/grafana/apiserver/server.go b/pkg/cmd/grafana/apiserver/server.go index 425df333d76..bee150feab3 100644 --- a/pkg/cmd/grafana/apiserver/server.go +++ b/pkg/cmd/grafana/apiserver/server.go @@ -12,9 +12,9 @@ import ( "k8s.io/client-go/tools/clientcmd" netutils "k8s.io/utils/net" - "github.com/grafana/grafana/pkg/registry/apis/datasource" "github.com/grafana/grafana/pkg/registry/apis/example" "github.com/grafana/grafana/pkg/registry/apis/featuretoggle" + "github.com/grafana/grafana/pkg/server" "github.com/grafana/grafana/pkg/services/featuremgmt" grafanaAPIServer "github.com/grafana/grafana/pkg/services/grafana-apiserver" "github.com/grafana/grafana/pkg/services/grafana-apiserver/utils" @@ -58,7 +58,7 @@ func (o *APIServerOptions) loadAPIGroupBuilders(args []string) error { } o.builders = append(o.builders, featuretoggle.NewFeatureFlagAPIBuilder(features)) case "testdata.datasource.grafana.app": - ds, err := datasource.NewStandaloneDatasource(g) + ds, err := server.InitializeDataSourceAPIServer(g) if err != nil { return err } diff --git a/pkg/registry/apis/datasource/standalone.go b/pkg/registry/apis/datasource/standalone.go index b4a1a1f3f17..07cbe6fbb0b 100644 --- a/pkg/registry/apis/datasource/standalone.go +++ b/pkg/registry/apis/datasource/standalone.go @@ -8,16 +8,13 @@ import ( common "github.com/grafana/grafana/pkg/apis/common/v0alpha1" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/setting" testdatasource "github.com/grafana/grafana/pkg/tsdb/grafana-testdata-datasource" ) -// NewStandaloneDatasource is a helper function to create a new datasource API server for a group. -// This currently has no dependencies and only works for testdata. In future iterations -// this will include here (or elsewhere) versions that can load config from HG api or -// the remote SQL directly. -func NewStandaloneDatasource(group string) (*DataSourceAPIBuilder, error) { +// NewTestDataAPIServer is a helper function to create a new datasource API server for a group. +// This currently builds its dependencies manually and only works for testdata. +func NewTestDataAPIServer(group string) (*DataSourceAPIBuilder, error) { pluginID := "grafana-testdata-datasource" if group != "testdata.datasource.grafana.app" { @@ -31,7 +28,7 @@ func NewStandaloneDatasource(group string) (*DataSourceAPIBuilder, error) { return nil, err } - _, pluginStore, dsService, dsCache, err := apiBuilderServices(cfg, pluginID) + accessControl, pluginStore, dsService, dsCache, err := apiBuilderServices(cfg, pluginID) if err != nil { return nil, err } @@ -49,7 +46,7 @@ func NewStandaloneDatasource(group string) (*DataSourceAPIBuilder, error) { td.JSONData, NewQuerierProvider(testsDataQuerierFactory), &TestDataPluginContextProvider{}, - acimpl.ProvideAccessControl(cfg), + accessControl, ) } diff --git a/pkg/server/wire.go b/pkg/server/wire.go index 64909565597..05ad52aef96 100644 --- a/pkg/server/wire.go +++ b/pkg/server/wire.go @@ -35,6 +35,7 @@ import ( "github.com/grafana/grafana/pkg/middleware/csrf" "github.com/grafana/grafana/pkg/middleware/loggermw" apiregistry "github.com/grafana/grafana/pkg/registry/apis" + "github.com/grafana/grafana/pkg/registry/apis/datasource" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol" @@ -459,3 +460,8 @@ func InitializeModuleServer(cfg *setting.Cfg, opts Options, apiOpts api.ServerOp wire.Build(wireExtsModuleServerSet) return &ModuleServer{}, nil } + +func InitializeDataSourceAPIServer(group string) (*datasource.DataSourceAPIBuilder, error) { + wire.Build(wireExtsDataSourceApiServerSet) + return &datasource.DataSourceAPIBuilder{}, nil +} diff --git a/pkg/server/wireexts_oss.go b/pkg/server/wireexts_oss.go index 5efd58cd50e..898f08d9912 100644 --- a/pkg/server/wireexts_oss.go +++ b/pkg/server/wireexts_oss.go @@ -11,6 +11,7 @@ import ( "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins/manager" "github.com/grafana/grafana/pkg/registry" + "github.com/grafana/grafana/pkg/registry/apis/datasource" "github.com/grafana/grafana/pkg/registry/backgroundsvcs" "github.com/grafana/grafana/pkg/registry/usagestatssvcs" "github.com/grafana/grafana/pkg/services/accesscontrol" @@ -137,3 +138,7 @@ var wireExtsModuleServerSet = wire.NewSet( NewModule, wireExtsBaseCLISet, ) + +var wireExtsDataSourceApiServerSet = wire.NewSet( + datasource.NewTestDataAPIServer, +)