Datasources: Add wireset for datasource.DataSourceAPIBuilder (#80914)

tidy up
This commit is contained in:
Will Browne 2024-01-22 15:21:27 +01:00 committed by GitHub
parent f3c64a7337
commit 2a0f1900d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 10 deletions

View File

@ -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
}

View File

@ -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,
)
}

View File

@ -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
}

View File

@ -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,
)