Datasources: Add service function to get by group, name, and namespace (#113066)

This commit is contained in:
Stephanie Hingtgen
2025-10-28 16:43:03 +00:00
committed by GitHub
parent 147ff4279b
commit 6a3dfacc95
6 changed files with 111 additions and 0 deletions
@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"github.com/grafana/authlib/types"
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana/pkg/infra/httpclient"
@@ -30,6 +31,19 @@ func (s *FakeDataSourceService) GetDataSource(ctx context.Context, query *dataso
return nil, datasources.ErrDataSourceNotFound
}
func (s *FakeDataSourceService) GetDataSourceInNamespace(ctx context.Context, namespace, name, group string) (*datasources.DataSource, error) {
ns, err := types.ParseNamespace(namespace)
if err != nil {
return nil, err
}
for _, dataSource := range s.DataSources {
if name == dataSource.UID && ns.OrgID == dataSource.OrgID && group == dataSource.Type {
return dataSource, nil
}
}
return nil, datasources.ErrDataSourceNotFound
}
func (s *FakeDataSourceService) GetDataSources(ctx context.Context, query *datasources.GetDataSourcesQuery) ([]*datasources.DataSource, error) {
var dataSources []*datasources.DataSource
for _, datasource := range s.DataSources {