mirror of https://github.com/grafana/grafana
Merge pull request #10896 from bergquist/provisioning_cfg_camelCase
Change naming format to camelCase for provisioning configspull/10910/head
commit
3091697a2c
@ -0,0 +1,12 @@ |
||||
- name: 'general dashboards' |
||||
org_id: 2 |
||||
folder: 'developers' |
||||
editable: true |
||||
type: file |
||||
options: |
||||
path: /var/lib/grafana/dashboards |
||||
|
||||
- name: 'default' |
||||
type: file |
||||
options: |
||||
path: /var/lib/grafana/dashboards |
@ -0,0 +1,109 @@ |
||||
package datasources |
||||
|
||||
import ( |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
|
||||
"github.com/grafana/grafana/pkg/log" |
||||
"gopkg.in/yaml.v2" |
||||
) |
||||
|
||||
type configReader struct { |
||||
log log.Logger |
||||
} |
||||
|
||||
func (cr *configReader) readConfig(path string) ([]*DatasourcesAsConfig, error) { |
||||
var datasources []*DatasourcesAsConfig |
||||
|
||||
files, err := ioutil.ReadDir(path) |
||||
if err != nil { |
||||
cr.log.Error("cant read datasource provisioning files from directory", "path", path) |
||||
return datasources, nil |
||||
} |
||||
|
||||
for _, file := range files { |
||||
if strings.HasSuffix(file.Name(), ".yaml") || strings.HasSuffix(file.Name(), ".yml") { |
||||
datasource, err := cr.parseDatasourceConfig(path, file) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if datasource != nil { |
||||
datasources = append(datasources, datasource) |
||||
} |
||||
} |
||||
} |
||||
|
||||
err = validateDefaultUniqueness(datasources) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return datasources, nil |
||||
} |
||||
|
||||
func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*DatasourcesAsConfig, error) { |
||||
filename, _ := filepath.Abs(filepath.Join(path, file.Name())) |
||||
yamlFile, err := ioutil.ReadFile(filename) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
var apiVersion *ConfigVersion |
||||
err = yaml.Unmarshal(yamlFile, &apiVersion) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if apiVersion.ApiVersion > 0 { |
||||
var v1 *DatasourcesAsConfigV1 |
||||
err = yaml.Unmarshal(yamlFile, &v1) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return v1.mapToDatasourceFromConfig(apiVersion.ApiVersion), nil |
||||
} |
||||
|
||||
var v0 *DatasourcesAsConfigV0 |
||||
err = yaml.Unmarshal(yamlFile, &v0) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
cr.log.Warn("[Deprecated] the datasource provisioning config is outdated. please upgrade", "filename", filename) |
||||
|
||||
return v0.mapToDatasourceFromConfig(apiVersion.ApiVersion), nil |
||||
} |
||||
|
||||
func validateDefaultUniqueness(datasources []*DatasourcesAsConfig) error { |
||||
defaultCount := 0 |
||||
for i := range datasources { |
||||
if datasources[i].Datasources == nil { |
||||
continue |
||||
} |
||||
|
||||
for _, ds := range datasources[i].Datasources { |
||||
if ds.OrgId == 0 { |
||||
ds.OrgId = 1 |
||||
} |
||||
|
||||
if ds.IsDefault { |
||||
defaultCount++ |
||||
if defaultCount > 1 { |
||||
return ErrInvalidConfigToManyDefault |
||||
} |
||||
} |
||||
} |
||||
|
||||
for _, ds := range datasources[i].DeleteDatasources { |
||||
if ds.OrgId == 0 { |
||||
ds.OrgId = 1 |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
} |
@ -1,23 +1,30 @@ |
||||
apiVersion: 1 |
||||
|
||||
datasources: |
||||
- name: name |
||||
type: type |
||||
access: proxy |
||||
org_id: 2 |
||||
orgId: 2 |
||||
url: url |
||||
password: password |
||||
user: user |
||||
database: database |
||||
basic_auth: true |
||||
basic_auth_user: basic_auth_user |
||||
basic_auth_password: basic_auth_password |
||||
with_credentials: true |
||||
is_default: true |
||||
json_data: |
||||
basicAuth: true |
||||
basicAuthUser: basic_auth_user |
||||
basicAuthPassword: basic_auth_password |
||||
withCredentials: true |
||||
isDefault: true |
||||
jsonData: |
||||
graphiteVersion: "1.1" |
||||
tlsAuth: true |
||||
tlsAuthWithCACert: true |
||||
secure_json_data: |
||||
secureJsonData: |
||||
tlsCACert: "MjNOcW9RdkbUDHZmpco2HCYzVq9dE+i6Yi+gmUJotq5CDA==" |
||||
tlsClientCert: "ckN0dGlyMXN503YNfjTcf9CV+GGQneN+xmAclQ==" |
||||
tlsClientKey: "ZkN4aG1aNkja/gKAB1wlnKFIsy2SRDq4slrM0A==" |
||||
editable: true |
||||
version: 10 |
||||
|
||||
deleteDatasources: |
||||
- name: old-graphite3 |
||||
orgId: 2 |
||||
|
@ -0,0 +1,28 @@ |
||||
datasources: |
||||
- name: name |
||||
type: type |
||||
access: proxy |
||||
org_id: 2 |
||||
url: url |
||||
password: password |
||||
user: user |
||||
database: database |
||||
basic_auth: true |
||||
basic_auth_user: basic_auth_user |
||||
basic_auth_password: basic_auth_password |
||||
with_credentials: true |
||||
is_default: true |
||||
json_data: |
||||
graphiteVersion: "1.1" |
||||
tlsAuth: true |
||||
tlsAuthWithCACert: true |
||||
secure_json_data: |
||||
tlsCACert: "MjNOcW9RdkbUDHZmpco2HCYzVq9dE+i6Yi+gmUJotq5CDA==" |
||||
tlsClientCert: "ckN0dGlyMXN503YNfjTcf9CV+GGQneN+xmAclQ==" |
||||
tlsClientKey: "ZkN4aG1aNkja/gKAB1wlnKFIsy2SRDq4slrM0A==" |
||||
editable: true |
||||
version: 10 |
||||
|
||||
delete_datasources: |
||||
- name: old-graphite3 |
||||
org_id: 2 |
Loading…
Reference in new issue