From 6564abd5f3984d56ca533672a33ba4c5f4eaf5ea Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 24 Jul 2018 22:09:33 +0900 Subject: [PATCH] get regions from after datasource save --- .../datasource/cloudwatch/config_ctrl.ts | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts index 1ff744854f5..7ee6b9dea43 100644 --- a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts @@ -1,19 +1,20 @@ +import _ from 'lodash'; export class CloudWatchConfigCtrl { static templateUrl = 'partials/config.html'; current: any; - $http: any; + datasourceSrv: any; accessKeyExist = false; secretKeyExist = false; /** @ngInject */ - constructor($scope, $http) { + constructor($scope, datasourceSrv) { this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp'; this.current.jsonData.authType = this.current.jsonData.authType || 'credentials'; this.accessKeyExist = this.current.secureJsonFields.accessKey; this.secretKeyExist = this.current.secureJsonFields.secretKey; - this.$http = $http; + this.datasourceSrv = datasourceSrv; this.getRegions(); } @@ -40,22 +41,41 @@ export class CloudWatchConfigCtrl { { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' }, ]; - regions = []; + regions = [ + 'ap-northeast-1', + 'ap-northeast-2', + 'ap-northeast-3', + 'ap-south-1', + 'ap-southeast-1', + 'ap-southeast-2', + 'ca-central-1', + 'cn-north-1', + 'cn-northwest-1', + 'eu-central-1', + 'eu-north-1', + 'eu-west-1', + 'eu-west-2', + 'eu-west-3', + 'me-south-1', + 'sa-east-1', + 'us-east-1', + 'us-east-2', + 'us-gov-east-1', + 'us-gov-west-1', + 'us-iso-east-1', + 'us-isob-east-1', + 'us-west-1', + 'us-west-2', + ]; getRegions() { - this.$http.get('https://ip-ranges.amazonaws.com/ip-ranges.json').then(ip_ranges => { - let regions = {}; - ip_ranges.data.prefixes - .map(p => { - return p.region; - }) - .filter(r => { - return r !== 'GLOBAL'; - }) - .forEach(r => { - regions[r] = true; - }); - this.regions = Object.keys(regions).sort(); - }); + this.datasourceSrv + .loadDatasource(this.current.name) + .then(ds => { + return ds.getRegions(); + }) + .then(regions => { + this.regions = _.uniq(this.regions.concat(_.map(regions, 'value'))); + }); } }