Alerting: update rule test endpoints to respect data source permissions (#47169)

* make eval.Evaluator an interface
* inject Evaluator to TestingApiSrv
* move conditionEval to RouteTestGrafanaRuleConfig because it is the only place where it is used
* update rule test api to check data source permissions
This commit is contained in:
Yuriy Tseretyan
2022-04-01 20:00:23 -04:00
committed by GitHub
parent 51114527dc
commit e94d0c1b96
8 changed files with 497 additions and 50 deletions

View File

@@ -0,0 +1,31 @@
package datasources
import (
"context"
"github.com/grafana/grafana/pkg/models"
)
type FakeCacheService struct {
DataSources []*models.DataSource
}
var _ CacheService = &FakeCacheService{}
func (c *FakeCacheService) GetDatasource(ctx context.Context, datasourceID int64, user *models.SignedInUser, skipCache bool) (*models.DataSource, error) {
for _, datasource := range c.DataSources {
if datasource.Id == datasourceID {
return datasource, nil
}
}
return nil, models.ErrDataSourceNotFound
}
func (c *FakeCacheService) GetDatasourceByUID(ctx context.Context, datasourceUID string, user *models.SignedInUser, skipCache bool) (*models.DataSource, error) {
for _, datasource := range c.DataSources {
if datasource.Uid == datasourceUID {
return datasource, nil
}
}
return nil, models.ErrDataSourceNotFound
}