From e96dd1b12a9029f31c29dc78ab0d9d65728c5100 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 26 Aug 2025 12:21:54 +0300 Subject: [PATCH] comments --- pkg/registry/apis/datasource/openapi.go | 2 +- pkg/registry/apis/datasource/plugincontext.go | 8 +++++--- pkg/registry/apis/datasource/register.go | 13 ++++++------- pkg/server/wire_gen.go | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/registry/apis/datasource/openapi.go b/pkg/registry/apis/datasource/openapi.go index 0cf5cf0eefe..e039fcc9d6e 100644 --- a/pkg/registry/apis/datasource/openapi.go +++ b/pkg/registry/apis/datasource/openapi.go @@ -138,7 +138,7 @@ func (b *DataSourceAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.Op op.Tags = append(op.Tags, "Route") // Custom resource? } } - oas.Paths.Paths[prefix+k] = v // TODO add namespace + name parameters + oas.Paths.Paths[prefix+k] = v } } return oas, err diff --git a/pkg/registry/apis/datasource/plugincontext.go b/pkg/registry/apis/datasource/plugincontext.go index c98aa4b8d8f..a0525030dcb 100644 --- a/pkg/registry/apis/datasource/plugincontext.go +++ b/pkg/registry/apis/datasource/plugincontext.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "github.com/grafana/authlib/types" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana/pkg/apimachinery/identity" datasourceV0 "github.com/grafana/grafana/pkg/apis/datasource/v0alpha1" @@ -12,6 +11,7 @@ import ( "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" + "github.com/grafana/grafana/pkg/setting" ) // This provides access to settings saved in the database. @@ -50,13 +50,15 @@ type PluginContextWrapper interface { func ProvideDefaultPluginConfigs( dsService datasources.DataSourceService, dsCache datasources.CacheService, - contextProvider *plugincontext.Provider) ScopedPluginDatasourceProvider { + contextProvider *plugincontext.Provider, + cfg *setting.Cfg, +) ScopedPluginDatasourceProvider { return &cachingDatasourceProvider{ dsService: dsService, dsCache: dsCache, contextProvider: contextProvider, converter: &converter{ - mapper: types.OrgNamespaceFormatter, // TODO -- from cfg!!! + mapper: request.GetNamespaceMapper(cfg), }, } } diff --git a/pkg/registry/apis/datasource/register.go b/pkg/registry/apis/datasource/register.go index 06afd325d6f..50cd8047205 100644 --- a/pkg/registry/apis/datasource/register.go +++ b/pkg/registry/apis/datasource/register.go @@ -22,7 +22,6 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/promlib/models" - "github.com/grafana/grafana/pkg/registry/apis/datasource/hardcoded" "github.com/grafana/grafana/pkg/registry/apis/query/queryschema" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/apiserver/builder" @@ -42,11 +41,11 @@ type DataSourceAPIBuilder struct { datasourceResourceInfo utils.ResourceInfo pluginJSON plugins.JSONData - client PluginClient // will only ever be called with the same pluginid! + client PluginClient // will only ever be called with the same plugin id! datasources PluginDatasourceProvider contextProvider PluginContextWrapper accessControl accesscontrol.AccessControl - schemaProvider func() (*datasourceV0.DataSourceOpenAPIExtension, error) // TODO? include query types + schemaProvider func() (*datasourceV0.DataSourceOpenAPIExtension, error) queryTypes *queryV0.QueryTypeDefinitionList log log.Logger } @@ -98,10 +97,10 @@ func RegisterAPIService( return nil, err } - // HARDCODE schema access - if ds.ID == "grafana-testdata-datasource" { - builder.schemaProvider = hardcoded.TestdataOpenAPIExtension - } + // TODO: load the schema provider from a static manifest + // if ds.ID == "grafana-testdata-datasource" { + // builder.schemaProvider = hardcoded.TestdataOpenAPIExtension + // } apiRegistrar.RegisterAPI(builder) } diff --git a/pkg/server/wire_gen.go b/pkg/server/wire_gen.go index 2b5d43803c4..c46f58068ea 100644 --- a/pkg/server/wire_gen.go +++ b/pkg/server/wire_gen.go @@ -730,7 +730,7 @@ func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api if err != nil { return nil, err } - scopedPluginDatasourceProvider := datasource.ProvideDefaultPluginConfigs(service15, cacheServiceImpl, plugincontextProvider) + scopedPluginDatasourceProvider := datasource.ProvideDefaultPluginConfigs(service15, cacheServiceImpl, plugincontextProvider, cfg) v := builder.ProvideDefaultBuildHandlerChainFuncFromBuilders() aggregatorRunner := aggregatorrunner.ProvideNoopAggregatorConfigurator() playlistAppInstaller, err := playlist.RegisterAppInstaller(playlistService, cfg, featureToggles) @@ -1306,7 +1306,7 @@ func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interfac if err != nil { return nil, err } - scopedPluginDatasourceProvider := datasource.ProvideDefaultPluginConfigs(service15, cacheServiceImpl, plugincontextProvider) + scopedPluginDatasourceProvider := datasource.ProvideDefaultPluginConfigs(service15, cacheServiceImpl, plugincontextProvider, cfg) v := builder.ProvideDefaultBuildHandlerChainFuncFromBuilders() aggregatorRunner := aggregatorrunner.ProvideNoopAggregatorConfigurator() playlistAppInstaller, err := playlist.RegisterAppInstaller(playlistService, cfg, featureToggles)