Provisioning: Validate that datasource access field equals to direct or proxy (#26440)

* Validate that datasource access field equals to allowed value (direct or proxy)
This commit is contained in:
Maksim Nabokikh
2020-07-20 10:01:25 +02:00
committed by GitHub
parent c298653623
commit a1f40195be
3 changed files with 23 additions and 3 deletions
@@ -7,6 +7,7 @@ import (
"strings"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"gopkg.in/yaml.v2"
)
@@ -36,7 +37,7 @@ func (cr *configReader) readConfig(path string) ([]*configs, error) {
}
}
err = validateDefaultUniqueness(datasources)
err = cr.validateDefaultUniqueness(datasources)
if err != nil {
return nil, err
}
@@ -82,7 +83,7 @@ func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*c
return v0.mapToDatasourceFromConfig(apiVersion.APIVersion), nil
}
func validateDefaultUniqueness(datasources []*configs) error {
func (cr *configReader) validateDefaultUniqueness(datasources []*configs) error {
defaultCount := map[int64]int{}
for i := range datasources {
if datasources[i].Datasources == nil {
@@ -95,7 +96,12 @@ func validateDefaultUniqueness(datasources []*configs) error {
}
if ds.Access == "" {
ds.Access = "proxy"
ds.Access = models.DS_ACCESS_PROXY
}
if ds.Access != models.DS_ACCESS_DIRECT && ds.Access != models.DS_ACCESS_PROXY {
cr.log.Warn("invalid access value, will use 'proxy' instead", "value", ds.Access)
ds.Access = models.DS_ACCESS_PROXY
}
if ds.IsDefault {