diff --git a/conf/datasources/datasources.yaml b/conf/datasources/datasources.yaml index 3364509d4aa..261e913a4de 100644 --- a/conf/datasources/datasources.yaml +++ b/conf/datasources/datasources.yaml @@ -32,10 +32,13 @@ datasources: # with_credentials: # # mark as default datasource. Max one per org # is_default: -# # json data -# json_data: '{"graphiteVersion":"0.9"}' -# # json object of data that will be encrypted in UI. -# secure_json_fields: '' +# # fields that will be converted to json and stored in json_data +# json_data: +# graphiteVersion: "1.1" +# tlsAuth: true +# tlsAuthWithCACert: true +# # json object of data that will be encrypted. +# secure_json_data: '' # # including this value guarantees that instance with old configs cannot # # overwrite your last change. # version: 1 diff --git a/pkg/services/provisioning/datasources/datasources_test.go b/pkg/services/provisioning/datasources/datasources_test.go index 9f8f8fe3551..f3252c28d9d 100644 --- a/pkg/services/provisioning/datasources/datasources_test.go +++ b/pkg/services/provisioning/datasources/datasources_test.go @@ -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") }) diff --git a/pkg/services/provisioning/datasources/test-configs/all-properties/all-properties.yaml b/pkg/services/provisioning/datasources/test-configs/all-properties/all-properties.yaml index eb0ac561363..af0d3009a4c 100644 --- a/pkg/services/provisioning/datasources/test-configs/all-properties/all-properties.yaml +++ b/pkg/services/provisioning/datasources/test-configs/all-properties/all-properties.yaml @@ -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 diff --git a/pkg/services/provisioning/datasources/types.go b/pkg/services/provisioning/datasources/types.go index 5ec52349485..ee2175d6a90 100644 --- a/pkg/services/provisioning/datasources/types.go +++ b/pkg/services/provisioning/datasources/types.go @@ -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{