mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 10:24:54 -06:00
datasources as cfg: convert yaml map into json for jsonData
This commit is contained in:
parent
6267ef1391
commit
87983021e2
@ -32,10 +32,13 @@ datasources:
|
||||
# with_credentials:
|
||||
# # <bool> mark as default datasource. Max one per org
|
||||
# is_default:
|
||||
# # <string> json data
|
||||
# json_data: '{"graphiteVersion":"0.9"}'
|
||||
# # <string> json object of data that will be encrypted in UI.
|
||||
# secure_json_fields: ''
|
||||
# # <map> fields that will be converted to json and stored in json_data
|
||||
# json_data:
|
||||
# graphiteVersion: "1.1"
|
||||
# tlsAuth: true
|
||||
# tlsAuthWithCACert: true
|
||||
# # <string> json object of data that will be encrypted.
|
||||
# secure_json_data: ''
|
||||
# # <int> including this value guarantees that instance with old configs cannot
|
||||
# # overwrite your last change.
|
||||
# version: 1
|
||||
|
@ -146,6 +146,16 @@ func TestDatasourceAsConfig(t *testing.T) {
|
||||
So(ds.IsDefault, ShouldBeTrue)
|
||||
So(ds.Editable, ShouldBeTrue)
|
||||
|
||||
So(len(ds.JsonData), ShouldBeGreaterThan, 2)
|
||||
So(ds.JsonData["graphiteVersion"], ShouldEqual, "1.1")
|
||||
So(ds.JsonData["tlsAuth"], ShouldEqual, true)
|
||||
So(ds.JsonData["tlsAuthWithCACert"], ShouldEqual, true)
|
||||
|
||||
So(len(ds.SecureJsonData), ShouldBeGreaterThan, 2)
|
||||
So(ds.SecureJsonData["tlsCACert"], ShouldEqual, "MjNOcW9RdkbUDHZmpco2HCYzVq9dE+i6Yi+gmUJotq5CDA==")
|
||||
So(ds.SecureJsonData["tlsClientCert"], ShouldEqual, "ckN0dGlyMXN503YNfjTcf9CV+GGQneN+xmAclQ==")
|
||||
So(ds.SecureJsonData["tlsClientKey"], ShouldEqual, "ZkN4aG1aNkja/gKAB1wlnKFIsy2SRDq4slrM0A==")
|
||||
|
||||
dstwo := cfg[1].Datasources[0]
|
||||
So(dstwo.Name, ShouldEqual, "name2")
|
||||
})
|
||||
|
@ -12,6 +12,12 @@ datasources:
|
||||
basic_auth_password: basic_auth_password
|
||||
with_credentials: true
|
||||
is_default: true
|
||||
json_data: '{"graphiteVersion":"0.9"}'
|
||||
secure_json_fields: ''
|
||||
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
|
||||
|
@ -17,27 +17,29 @@ type DataSourceFromConfig struct {
|
||||
OrgId int64 `json:"org_id" yaml:"org_id"`
|
||||
Version int `json:"version" yaml:"version"`
|
||||
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Access string `json:"access" yaml:"access"`
|
||||
Url string `json:"url" yaml:"url"`
|
||||
Password string `json:"password" yaml:"password"`
|
||||
User string `json:"user" yaml:"user"`
|
||||
Database string `json:"database" yaml:"database"`
|
||||
BasicAuth bool `json:"basic_auth" yaml:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user" yaml:"basic_auth_user"`
|
||||
BasicAuthPassword string `json:"basic_auth_password" yaml:"basic_auth_password"`
|
||||
WithCredentials bool `json:"with_credentials" yaml:"with_credentials"`
|
||||
IsDefault bool `json:"is_default" yaml:"is_default"`
|
||||
JsonData string `json:"json_data" yaml:"json_data"`
|
||||
SecureJsonData map[string]string `json:"secure_json_data" yaml:"secure_json_data"`
|
||||
Editable bool `json:"editable" yaml:"editable"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Access string `json:"access" yaml:"access"`
|
||||
Url string `json:"url" yaml:"url"`
|
||||
Password string `json:"password" yaml:"password"`
|
||||
User string `json:"user" yaml:"user"`
|
||||
Database string `json:"database" yaml:"database"`
|
||||
BasicAuth bool `json:"basic_auth" yaml:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user" yaml:"basic_auth_user"`
|
||||
BasicAuthPassword string `json:"basic_auth_password" yaml:"basic_auth_password"`
|
||||
WithCredentials bool `json:"with_credentials" yaml:"with_credentials"`
|
||||
IsDefault bool `json:"is_default" yaml:"is_default"`
|
||||
JsonData map[string]interface{} `json:"json_data" yaml:"json_data"`
|
||||
SecureJsonData map[string]string `json:"secure_json_data" yaml:"secure_json_data"`
|
||||
Editable bool `json:"editable" yaml:"editable"`
|
||||
}
|
||||
|
||||
func createInsertCommand(ds *DataSourceFromConfig) *models.AddDataSourceCommand {
|
||||
jsonData, err := simplejson.NewJson([]byte(ds.JsonData))
|
||||
if err != nil {
|
||||
jsonData = simplejson.New()
|
||||
jsonData := simplejson.New()
|
||||
if len(ds.JsonData) > 0 {
|
||||
for k, v := range ds.JsonData {
|
||||
jsonData.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
return &models.AddDataSourceCommand{
|
||||
@ -61,9 +63,11 @@ func createInsertCommand(ds *DataSourceFromConfig) *models.AddDataSourceCommand
|
||||
}
|
||||
|
||||
func createUpdateCommand(ds *DataSourceFromConfig, id int64) *models.UpdateDataSourceCommand {
|
||||
jsonData, err := simplejson.NewJson([]byte(ds.JsonData))
|
||||
if err != nil {
|
||||
jsonData = simplejson.New()
|
||||
jsonData := simplejson.New()
|
||||
if len(ds.JsonData) > 0 {
|
||||
for k, v := range ds.JsonData {
|
||||
jsonData.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
return &models.UpdateDataSourceCommand{
|
||||
|
Loading…
Reference in New Issue
Block a user