From 330c1b945e4d6d9be2edfde2971fc6404ee73b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 14 Dec 2016 21:05:12 +0100 Subject: [PATCH] refactor(datasource): refactoring datasource secure json fields handling, #6697, #6692 --- pkg/api/datasources.go | 9 ++------- pkg/api/dtos/models.go | 10 +--------- public/app/features/plugins/ds_edit_ctrl.ts | 2 +- .../plugins/partials/ds_http_settings.html | 18 +++++++++--------- .../datasource/cloudwatch/config_ctrl.ts | 10 ++-------- 5 files changed, 15 insertions(+), 34 deletions(-) diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index f0c022c1622..707e351d6b5 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -206,17 +206,12 @@ func convertModelToDtos(ds *m.DataSource) dtos.DataSource { WithCredentials: ds.WithCredentials, IsDefault: ds.IsDefault, JsonData: ds.JsonData, - } - - if len(ds.SecureJsonData) > 0 { - dto.TLSAuth.CACertSet = len(ds.SecureJsonData["tlsCACert"]) > 0 - dto.TLSAuth.ClientCertSet = len(ds.SecureJsonData["tlsClientCert"]) > 0 - dto.TLSAuth.ClientKeySet = len(ds.SecureJsonData["tlsClientKey"]) > 0 + SecureJsonFields: map[string]bool{}, } for k, v := range ds.SecureJsonData { if len(v) > 0 { - dto.EncryptedFields = append(dto.EncryptedFields, k) + dto.SecureJsonFields[k] = true } } diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index e9efd1b7c01..13dbe4ea32a 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -81,15 +81,7 @@ type DataSource struct { WithCredentials bool `json:"withCredentials"` IsDefault bool `json:"isDefault"` JsonData *simplejson.Json `json:"jsonData,omitempty"` - TLSAuth TLSAuth `json:"tlsAuth,omitempty"` - EncryptedFields []string `json:"encryptedFields"` -} - -// TLSAuth is used to show if TLS certs have been uploaded already -type TLSAuth struct { - CACertSet bool `json:"tlsCACertSet"` - ClientCertSet bool `json:"tlsClientCertSet"` - ClientKeySet bool `json:"tlsClientKeySet"` + SecureJsonFields map[string]bool `json:"secureJsonFields"` } type DataSourceList []DataSource diff --git a/public/app/features/plugins/ds_edit_ctrl.ts b/public/app/features/plugins/ds_edit_ctrl.ts index 42e4f410315..f1200f01764 100644 --- a/public/app/features/plugins/ds_edit_ctrl.ts +++ b/public/app/features/plugins/ds_edit_ctrl.ts @@ -14,7 +14,7 @@ var defaults = { url: '', access: 'proxy', jsonData: {}, - encryptedFields: [] + secureJsonFields: {}, }; var datasourceCreated = false; diff --git a/public/app/features/plugins/partials/ds_http_settings.html b/public/app/features/plugins/partials/ds_http_settings.html index 6c116eef193..f371097daf6 100644 --- a/public/app/features/plugins/partials/ds_http_settings.html +++ b/public/app/features/plugins/partials/ds_http_settings.html @@ -89,13 +89,13 @@
-
+
-
+
- reset + reset
@@ -104,12 +104,12 @@
-
+
-
+
- reset + reset
@@ -117,12 +117,12 @@
-
+
-
+
- reset + reset
diff --git a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts index a60cd6ae8c9..b04533bd20c 100644 --- a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts @@ -15,14 +15,8 @@ export class CloudWatchConfigCtrl { this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp'; this.current.jsonData.authType = this.current.jsonData.authType || 'credentials'; - for (let key of this.current.encryptedFields) { - if (key === "accessKey") { - this.accessKeyExist = true; - } - if (key === "secretKey") { - this.secretKeyExist = true; - } - } + this.accessKeyExist = this.current.secureJsonFields.accessKey; + this.secretKeyExist = this.current.secureJsonFields.secretKey; } resetAccessKey() {