From 7bc1c3cc1cb015a7a2e3f942b49e1dec67f970e4 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 24 Nov 2016 16:24:47 +0100 Subject: [PATCH] feat(cloudwatch): make it possible to reset keys closes #6697 --- pkg/api/cloudwatch/metrics.go | 30 ++-------------- pkg/api/datasources.go | 6 ++++ pkg/api/dtos/models.go | 36 +++++++++---------- public/app/features/plugins/ds_edit_ctrl.ts | 1 - .../datasource/cloudwatch/config_ctrl.ts | 20 +++++++++++ .../cloudwatch/partials/config.html | 24 +++++++------ 6 files changed, 61 insertions(+), 56 deletions(-) diff --git a/pkg/api/cloudwatch/metrics.go b/pkg/api/cloudwatch/metrics.go index 5744ecad45e..1880c6375b0 100644 --- a/pkg/api/cloudwatch/metrics.go +++ b/pkg/api/cloudwatch/metrics.go @@ -192,21 +192,6 @@ func handleGetMetrics(req *cwRequest, c *middleware.Context) { } } else { var err error - /* - assumeRoleArn := req.DataSource.JsonData.Get("assumeRoleArn").MustString() - accessKey := req.DataSource.JsonData.Get("accessKey").MustString() - secretKey := req.DataSource.JsonData.Get("secretKey").MustString() - - cwData := &datasourceInfo{ - AssumeRoleArn: assumeRoleArn, - Region: req.Region, - Namespace: reqParam.Parameters.Namespace, - Profile: req.DataSource.Database, - AccessKey: accessKey, - SecretKey: secretKey, - } - */ - cwData := req.GetDatasourceInfo() cwData.Namespace = reqParam.Parameters.Namespace @@ -243,19 +228,10 @@ func handleGetDimensions(req *cwRequest, c *middleware.Context) { } } else { var err error - assumeRoleArn := req.DataSource.JsonData.Get("assumeRoleArn").MustString() - accessKey := req.DataSource.JsonData.Get("accessKey").MustString() - secretKey := req.DataSource.JsonData.Get("secretKey").MustString() + dsInfo := req.GetDatasourceInfo() + dsInfo.Namespace = reqParam.Parameters.Namespace - cwDatasource := &datasourceInfo{ - Region: req.Region, - Namespace: reqParam.Parameters.Namespace, - Profile: req.DataSource.Database, - AssumeRoleArn: assumeRoleArn, - AccessKey: accessKey, - SecretKey: secretKey, - } - if dimensionValues, err = getDimensionsForCustomMetrics(cwDatasource, getAllMetrics); err != nil { + if dimensionValues, err = getDimensionsForCustomMetrics(dsInfo, getAllMetrics); err != nil { c.JsonApiErr(500, "Unable to call AWS API", err) return } diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 87c743c9ce6..cc305221817 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -215,5 +215,11 @@ func convertModelToDtos(ds *m.DataSource) dtos.DataSource { dto.TLSAuth.ClientKeySet = len(ds.SecureJsonData["tlsClientKey"]) > 0 } + for k, v := range ds.SecureJsonData { + if len(v) > 0 { + dto.EncryptedFields = append(dto.EncryptedFields, k) + } + } + return dto } diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 9f8ae329fec..17ac39fa344 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -64,24 +64,24 @@ type DashboardRedirect struct { } type DataSource struct { - Id int64 `json:"id"` - OrgId int64 `json:"orgId"` - Name string `json:"name"` - Type string `json:"type"` - TypeLogoUrl string `json:"typeLogoUrl"` - Access m.DsAccess `json:"access"` - Url string `json:"url"` - Password string `json:"password"` - User string `json:"user"` - Database string `json:"database"` - BasicAuth bool `json:"basicAuth"` - BasicAuthUser string `json:"basicAuthUser"` - BasicAuthPassword string `json:"basicAuthPassword"` - WithCredentials bool `json:"withCredentials"` - IsDefault bool `json:"isDefault"` - JsonData *simplejson.Json `json:"jsonData,omitempty"` - SecureJsonData map[string]string `json:"secureJsonData,omitempty"` - TLSAuth TLSAuth `json:"tlsAuth,omitempty"` + Id int64 `json:"id"` + OrgId int64 `json:"orgId"` + Name string `json:"name"` + Type string `json:"type"` + TypeLogoUrl string `json:"typeLogoUrl"` + Access m.DsAccess `json:"access"` + Url string `json:"url"` + Password string `json:"password"` + User string `json:"user"` + Database string `json:"database"` + BasicAuth bool `json:"basicAuth"` + BasicAuthUser string `json:"basicAuthUser"` + BasicAuthPassword string `json:"basicAuthPassword"` + 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 diff --git a/public/app/features/plugins/ds_edit_ctrl.ts b/public/app/features/plugins/ds_edit_ctrl.ts index 7ac29227001..9c808b188c4 100644 --- a/public/app/features/plugins/ds_edit_ctrl.ts +++ b/public/app/features/plugins/ds_edit_ctrl.ts @@ -68,7 +68,6 @@ export class DataSourceEditCtrl { this.backendSrv.get('/api/datasources/' + id).then(ds => { this.isNew = false; this.current = ds; - if (datasourceCreated) { datasourceCreated = false; this.testDatasource(); diff --git a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts index 8f9a8a970ba..a60cd6ae8c9 100644 --- a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts @@ -7,10 +7,30 @@ export class CloudWatchConfigCtrl { static templateUrl = 'partials/config.html'; current: any; + accessKeyExist: boolean = false; + secretKeyExist: boolean = false; + /** @ngInject */ constructor($scope) { 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; + } + } + } + + resetAccessKey() { + this.accessKeyExist = false; + } + + resetSecretKey() { + this.secretKeyExist = false; } authTypes = [ diff --git a/public/app/plugins/datasource/cloudwatch/partials/config.html b/public/app/plugins/datasource/cloudwatch/partials/config.html index 9a5a4c68cf5..a08ed8be100 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/config.html +++ b/public/app/plugins/datasource/cloudwatch/partials/config.html @@ -3,7 +3,7 @@
- +
@@ -14,18 +14,22 @@
- - - - AWS Access key id - + + + Reset +
- - - AWS Secret key - + + Reset +