Fixes linting errors in datasource provisioning. (#23515)
This commit is contained in:
@@ -14,8 +14,8 @@ type configReader struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (cr *configReader) readConfig(path string) ([]*DatasourcesAsConfig, error) {
|
||||
var datasources []*DatasourcesAsConfig
|
||||
func (cr *configReader) readConfig(path string) ([]*configs, error) {
|
||||
var datasources []*configs
|
||||
|
||||
files, err := ioutil.ReadDir(path)
|
||||
if err != nil {
|
||||
@@ -44,34 +44,34 @@ func (cr *configReader) readConfig(path string) ([]*DatasourcesAsConfig, error)
|
||||
return datasources, nil
|
||||
}
|
||||
|
||||
func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*DatasourcesAsConfig, error) {
|
||||
func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*configs, error) {
|
||||
filename, _ := filepath.Abs(filepath.Join(path, file.Name()))
|
||||
yamlFile, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var apiVersion *ConfigVersion
|
||||
var apiVersion *configVersion
|
||||
err = yaml.Unmarshal(yamlFile, &apiVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if apiVersion == nil {
|
||||
apiVersion = &ConfigVersion{ApiVersion: 0}
|
||||
apiVersion = &configVersion{APIVersion: 0}
|
||||
}
|
||||
|
||||
if apiVersion.ApiVersion > 0 {
|
||||
v1 := &DatasourcesAsConfigV1{log: cr.log}
|
||||
if apiVersion.APIVersion > 0 {
|
||||
v1 := &configsV1{log: cr.log}
|
||||
err = yaml.Unmarshal(yamlFile, v1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v1.mapToDatasourceFromConfig(apiVersion.ApiVersion), nil
|
||||
return v1.mapToDatasourceFromConfig(apiVersion.APIVersion), nil
|
||||
}
|
||||
|
||||
var v0 *DatasourcesAsConfigV0
|
||||
var v0 *configsV0
|
||||
err = yaml.Unmarshal(yamlFile, &v0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,10 +79,10 @@ func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*D
|
||||
|
||||
cr.log.Warn("[Deprecated] the datasource provisioning config is outdated. please upgrade", "filename", filename)
|
||||
|
||||
return v0.mapToDatasourceFromConfig(apiVersion.ApiVersion), nil
|
||||
return v0.mapToDatasourceFromConfig(apiVersion.APIVersion), nil
|
||||
}
|
||||
|
||||
func validateDefaultUniqueness(datasources []*DatasourcesAsConfig) error {
|
||||
func validateDefaultUniqueness(datasources []*configs) error {
|
||||
defaultCount := map[int64]int{}
|
||||
for i := range datasources {
|
||||
if datasources[i].Datasources == nil {
|
||||
@@ -90,21 +90,21 @@ func validateDefaultUniqueness(datasources []*DatasourcesAsConfig) error {
|
||||
}
|
||||
|
||||
for _, ds := range datasources[i].Datasources {
|
||||
if ds.OrgId == 0 {
|
||||
ds.OrgId = 1
|
||||
if ds.OrgID == 0 {
|
||||
ds.OrgID = 1
|
||||
}
|
||||
|
||||
if ds.IsDefault {
|
||||
defaultCount[ds.OrgId] = defaultCount[ds.OrgId] + 1
|
||||
if defaultCount[ds.OrgId] > 1 {
|
||||
defaultCount[ds.OrgID] = defaultCount[ds.OrgID] + 1
|
||||
if defaultCount[ds.OrgID] > 1 {
|
||||
return ErrInvalidConfigToManyDefault
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, ds := range datasources[i].DeleteDatasources {
|
||||
if ds.OrgId == 0 {
|
||||
ds.OrgId = 1
|
||||
if ds.OrgID == 0 {
|
||||
ds.OrgID = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user