mirror of
https://github.com/grafana/grafana.git
synced 2025-01-10 08:03:58 -06:00
Chore: Replace config with datasource in names (#81098)
This commit is contained in:
parent
3ea84e1b7f
commit
3b96eb854a
@ -23,7 +23,7 @@ type connectionAccess struct {
|
||||
pluginID string
|
||||
resourceInfo common.ResourceInfo
|
||||
tableConverter rest.TableConvertor
|
||||
configs PluginConfigProvider
|
||||
datasources PluginDatasourceProvider
|
||||
}
|
||||
|
||||
func (s *connectionAccess) New() runtime.Object {
|
||||
@ -53,9 +53,9 @@ func (s *connectionAccess) ConvertToTable(ctx context.Context, object runtime.Ob
|
||||
}
|
||||
|
||||
func (s *connectionAccess) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
return s.configs.GetDataSource(ctx, s.pluginID, name)
|
||||
return s.datasources.Get(ctx, s.pluginID, name)
|
||||
}
|
||||
|
||||
func (s *connectionAccess) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
|
||||
return s.configs.ListDatasources(ctx, s.pluginID)
|
||||
return s.datasources.List(ctx, s.pluginID)
|
||||
}
|
||||
|
@ -18,16 +18,16 @@ import (
|
||||
// This provides access to settings saved in the database.
|
||||
// Authorization checks will happen within each function, and the user in ctx will
|
||||
// limit which namespace/tenant/org we are talking to
|
||||
type PluginConfigProvider interface {
|
||||
// GetDataSource gets a specific datasource (that the user in context can see)
|
||||
GetDataSource(ctx context.Context, pluginID, uid string) (*v0alpha1.DataSourceConnection, error)
|
||||
type PluginDatasourceProvider interface {
|
||||
// Get gets a specific datasource (that the user in context can see)
|
||||
Get(ctx context.Context, pluginID, uid string) (*v0alpha1.DataSourceConnection, error)
|
||||
|
||||
// ListDatasources lists all data sources the user in context can see
|
||||
ListDatasources(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error)
|
||||
// List lists all data sources the user in context can see
|
||||
List(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error)
|
||||
|
||||
// Return settings (decrypted!) for a specific plugin
|
||||
// This will require "query" permission for the user in context
|
||||
GetDataSourceInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error)
|
||||
GetInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error)
|
||||
}
|
||||
|
||||
// PluginContext requires adding system settings (feature flags, etc) to the datasource config
|
||||
@ -38,25 +38,25 @@ type PluginContextWrapper interface {
|
||||
func ProvideDefaultPluginConfigs(
|
||||
dsService datasources.DataSourceService,
|
||||
dsCache datasources.CacheService,
|
||||
contextProvider *plugincontext.Provider) PluginConfigProvider {
|
||||
return &defaultPluginConfigProvider{
|
||||
contextProvider *plugincontext.Provider) PluginDatasourceProvider {
|
||||
return &defaultPluginDatasourceProvider{
|
||||
dsService: dsService,
|
||||
dsCache: dsCache,
|
||||
contextProvider: contextProvider,
|
||||
}
|
||||
}
|
||||
|
||||
type defaultPluginConfigProvider struct {
|
||||
type defaultPluginDatasourceProvider struct {
|
||||
dsService datasources.DataSourceService
|
||||
dsCache datasources.CacheService
|
||||
contextProvider *plugincontext.Provider
|
||||
}
|
||||
|
||||
var (
|
||||
_ PluginConfigProvider = (*defaultPluginConfigProvider)(nil)
|
||||
_ PluginDatasourceProvider = (*defaultPluginDatasourceProvider)(nil)
|
||||
)
|
||||
|
||||
func (q *defaultPluginConfigProvider) GetDataSource(ctx context.Context, pluginID, uid string) (*v0alpha1.DataSourceConnection, error) {
|
||||
func (q *defaultPluginDatasourceProvider) Get(ctx context.Context, pluginID, uid string) (*v0alpha1.DataSourceConnection, error) {
|
||||
info, err := request.NamespaceInfoFrom(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -72,7 +72,7 @@ func (q *defaultPluginConfigProvider) GetDataSource(ctx context.Context, pluginI
|
||||
return asConnection(ds, info.Value)
|
||||
}
|
||||
|
||||
func (q *defaultPluginConfigProvider) ListDatasources(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error) {
|
||||
func (q *defaultPluginDatasourceProvider) List(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error) {
|
||||
info, err := request.NamespaceInfoFrom(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -95,7 +95,7 @@ func (q *defaultPluginConfigProvider) ListDatasources(ctx context.Context, plugi
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (q *defaultPluginConfigProvider) GetDataSourceInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error) {
|
||||
func (q *defaultPluginDatasourceProvider) GetInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error) {
|
||||
if q.contextProvider == nil {
|
||||
// NOTE!!! this is only here for the standalone example
|
||||
// if we cleanup imports this can throw an error
|
||||
|
@ -36,7 +36,7 @@ type DataSourceAPIBuilder struct {
|
||||
|
||||
pluginJSON plugins.JSONData
|
||||
client plugins.Client // will only ever be called with the same pluginid!
|
||||
pluginsConfig PluginConfigProvider
|
||||
datasources PluginDatasourceProvider
|
||||
contextProvider PluginContextWrapper
|
||||
accessControl accesscontrol.AccessControl
|
||||
}
|
||||
@ -45,7 +45,7 @@ func RegisterAPIService(
|
||||
features featuremgmt.FeatureToggles,
|
||||
apiRegistrar grafanaapiserver.APIRegistrar,
|
||||
pluginClient plugins.Client, // access to everything
|
||||
pluginConfigs PluginConfigProvider,
|
||||
datasources PluginDatasourceProvider,
|
||||
contextProvider PluginContextWrapper,
|
||||
pluginStore pluginstore.Store,
|
||||
accessControl accesscontrol.AccessControl,
|
||||
@ -69,7 +69,7 @@ func RegisterAPIService(
|
||||
|
||||
builder, err = NewDataSourceAPIBuilder(ds.JSONData,
|
||||
pluginClient,
|
||||
pluginConfigs,
|
||||
datasources,
|
||||
contextProvider,
|
||||
accessControl,
|
||||
)
|
||||
@ -84,7 +84,7 @@ func RegisterAPIService(
|
||||
func NewDataSourceAPIBuilder(
|
||||
plugin plugins.JSONData,
|
||||
client plugins.Client,
|
||||
pluginsConfig PluginConfigProvider,
|
||||
datasources PluginDatasourceProvider,
|
||||
contextProvider PluginContextWrapper,
|
||||
accessControl accesscontrol.AccessControl) (*DataSourceAPIBuilder, error) {
|
||||
ri, err := resourceFromPluginID(plugin.ID)
|
||||
@ -96,7 +96,7 @@ func NewDataSourceAPIBuilder(
|
||||
connectionResourceInfo: ri,
|
||||
pluginJSON: plugin,
|
||||
client: client,
|
||||
pluginsConfig: pluginsConfig,
|
||||
datasources: datasources,
|
||||
contextProvider: contextProvider,
|
||||
accessControl: accessControl,
|
||||
}, nil
|
||||
@ -155,7 +155,7 @@ func (b *DataSourceAPIBuilder) GetAPIGroupInfo(
|
||||
conn := b.connectionResourceInfo
|
||||
storage[conn.StoragePath()] = &connectionAccess{
|
||||
pluginID: b.pluginJSON.ID,
|
||||
configs: b.pluginsConfig,
|
||||
datasources: b.datasources,
|
||||
resourceInfo: conn,
|
||||
tableConverter: utils.NewTableConverter(
|
||||
conn.GroupResource(),
|
||||
@ -199,7 +199,7 @@ func (b *DataSourceAPIBuilder) GetAPIGroupInfo(
|
||||
}
|
||||
|
||||
func (b *DataSourceAPIBuilder) getPluginContext(ctx context.Context, uid string) (backend.PluginContext, error) {
|
||||
instance, err := b.pluginsConfig.GetDataSourceInstanceSettings(ctx, b.pluginJSON.ID, uid)
|
||||
instance, err := b.datasources.GetInstanceSettings(ctx, b.pluginJSON.ID, uid)
|
||||
if err != nil {
|
||||
return backend.PluginContext{}, err
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ func NewTestDataAPIServer(group string) (*DataSourceAPIBuilder, error) {
|
||||
ID: pluginID,
|
||||
},
|
||||
testdatasource.ProvideService(), // the client
|
||||
&testdataPluginConfigProvider{
|
||||
&pluginDatasourceImpl{
|
||||
startup: v1.Now(),
|
||||
},
|
||||
&testdataPluginConfigProvider{}, // stub
|
||||
&pluginDatasourceImpl{}, // stub
|
||||
&actest.FakeAccessControl{ExpectedEvaluate: true},
|
||||
)
|
||||
}
|
||||
@ -56,30 +56,31 @@ func NewTestDataAPIServer(group string) (*DataSourceAPIBuilder, error) {
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("plugin %s not found", pluginID)
|
||||
}
|
||||
|
||||
return NewDataSourceAPIBuilder(
|
||||
td.JSONData,
|
||||
testdatasource.ProvideService(), // the client
|
||||
&defaultPluginConfigProvider{
|
||||
&defaultPluginDatasourceProvider{
|
||||
dsService: dsService,
|
||||
dsCache: dsCache,
|
||||
},
|
||||
&testdataPluginConfigProvider{}, // stub
|
||||
&pluginDatasourceImpl{}, // stub
|
||||
accessControl,
|
||||
)
|
||||
}
|
||||
|
||||
// Simple stub for standalone testing
|
||||
type testdataPluginConfigProvider struct {
|
||||
type pluginDatasourceImpl struct {
|
||||
startup v1.Time
|
||||
}
|
||||
|
||||
var (
|
||||
_ PluginConfigProvider = (*testdataPluginConfigProvider)(nil)
|
||||
_ PluginDatasourceProvider = (*pluginDatasourceImpl)(nil)
|
||||
)
|
||||
|
||||
// GetDataSource implements PluginConfigProvider.
|
||||
func (p *testdataPluginConfigProvider) GetDataSource(ctx context.Context, pluginID string, uid string) (*v0alpha1.DataSourceConnection, error) {
|
||||
all, err := p.ListDatasources(ctx, pluginID)
|
||||
// Get implements PluginDatasourceProvider.
|
||||
func (p *pluginDatasourceImpl) Get(ctx context.Context, pluginID string, uid string) (*v0alpha1.DataSourceConnection, error) {
|
||||
all, err := p.List(ctx, pluginID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -91,8 +92,8 @@ func (p *testdataPluginConfigProvider) GetDataSource(ctx context.Context, plugin
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
// ListDatasources implements PluginConfigProvider.
|
||||
func (p *testdataPluginConfigProvider) ListDatasources(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error) {
|
||||
// List implements PluginConfigProvider.
|
||||
func (p *pluginDatasourceImpl) List(ctx context.Context, pluginID string) (*v0alpha1.DataSourceConnectionList, error) {
|
||||
info, err := request.NamespaceInfoFrom(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -114,11 +115,11 @@ func (p *testdataPluginConfigProvider) ListDatasources(ctx context.Context, plug
|
||||
}
|
||||
|
||||
// PluginContextForDataSource implements PluginConfigProvider.
|
||||
func (*testdataPluginConfigProvider) GetDataSourceInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error) {
|
||||
func (*pluginDatasourceImpl) GetInstanceSettings(ctx context.Context, pluginID, uid string) (*backend.DataSourceInstanceSettings, error) {
|
||||
return &backend.DataSourceInstanceSettings{}, nil
|
||||
}
|
||||
|
||||
// PluginContextWrapper
|
||||
func (*testdataPluginConfigProvider) PluginContextForDataSource(ctx context.Context, datasourceSettings *backend.DataSourceInstanceSettings) (backend.PluginContext, error) {
|
||||
func (*pluginDatasourceImpl) PluginContextForDataSource(ctx context.Context, datasourceSettings *backend.DataSourceInstanceSettings) (backend.PluginContext, error) {
|
||||
return backend.PluginContext{DataSourceInstanceSettings: datasourceSettings}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user