9598ae6434
* extra data source read methods * update tests * more tests * fix more tests; actually initialize retriever instead of sending nil * moving GetAllDataSources isn't strictly required, so keep to minimal changes * better name for retriever logger Co-authored-by: Dafydd <72009875+dafydd-t@users.noreply.github.com> * add compile-time check for DS retriever impl --------- Co-authored-by: Dafydd <72009875+dafydd-t@users.noreply.github.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
)
|
|
|
|
// DataSourceRetrieverImpl implements DataSourceRetriever by delegating to a Store.
|
|
type DataSourceRetrieverImpl struct {
|
|
store Store
|
|
}
|
|
|
|
var _ DataSourceRetriever = (*DataSourceRetrieverImpl)(nil)
|
|
|
|
// ProvideDataSourceRetriever creates a DataSourceRetriever for wire injection.
|
|
func ProvideDataSourceRetriever(db db.DB, features featuremgmt.FeatureToggles) DataSourceRetriever {
|
|
dslogger := log.New("datasources-retriever")
|
|
store := &SqlStore{db: db, logger: dslogger, features: features}
|
|
return &DataSourceRetrieverImpl{store: store}
|
|
}
|
|
|
|
// GetDataSource gets a datasource.
|
|
func (r *DataSourceRetrieverImpl) GetDataSource(ctx context.Context, query *datasources.GetDataSourceQuery) (*datasources.DataSource, error) {
|
|
return r.store.GetDataSource(ctx, query)
|
|
}
|
|
|
|
// GetDataSourceInNamespace gets a datasource by namespace, name (datasource uid), and group (datasource type).
|
|
func (r *DataSourceRetrieverImpl) GetDataSourceInNamespace(ctx context.Context, namespace, name, group string) (*datasources.DataSource, error) {
|
|
return r.store.GetDataSourceInNamespace(ctx, namespace, name, group)
|
|
}
|