Просмотр исходного кода

get regions from after datasource save

Mitsuhiro Tanda 7 лет назад
Родитель
Сommit
6564abd5f3
1 измененных файлов с 38 добавлено и 18 удалено
  1. 38 18
      public/app/plugins/datasource/cloudwatch/config_ctrl.ts

+ 38 - 18
public/app/plugins/datasource/cloudwatch/config_ctrl.ts

@@ -1,19 +1,20 @@
+import _ from 'lodash';
 export class CloudWatchConfigCtrl {
 export class CloudWatchConfigCtrl {
   static templateUrl = 'partials/config.html';
   static templateUrl = 'partials/config.html';
   current: any;
   current: any;
-  $http: any;
+  datasourceSrv: any;
 
 
   accessKeyExist = false;
   accessKeyExist = false;
   secretKeyExist = false;
   secretKeyExist = false;
 
 
   /** @ngInject */
   /** @ngInject */
-  constructor($scope, $http) {
+  constructor($scope, datasourceSrv) {
     this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp';
     this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp';
     this.current.jsonData.authType = this.current.jsonData.authType || 'credentials';
     this.current.jsonData.authType = this.current.jsonData.authType || 'credentials';
 
 
     this.accessKeyExist = this.current.secureJsonFields.accessKey;
     this.accessKeyExist = this.current.secureJsonFields.accessKey;
     this.secretKeyExist = this.current.secureJsonFields.secretKey;
     this.secretKeyExist = this.current.secureJsonFields.secretKey;
-    this.$http = $http;
+    this.datasourceSrv = datasourceSrv;
     this.getRegions();
     this.getRegions();
   }
   }
 
 
@@ -40,22 +41,41 @@ export class CloudWatchConfigCtrl {
     { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
     { 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() {
   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')));
+      });
   }
   }
 }
 }