config_ctrl.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import _ from 'lodash';
  2. import DatasourceSrv from 'app/features/plugins/datasource_srv';
  3. import CloudWatchDatasource from './datasource';
  4. export class CloudWatchConfigCtrl {
  5. static templateUrl = 'partials/config.html';
  6. current: any;
  7. datasourceSrv: any;
  8. accessKeyExist = false;
  9. secretKeyExist = false;
  10. /** @ngInject */
  11. constructor($scope: any, datasourceSrv: DatasourceSrv) {
  12. this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp';
  13. this.current.jsonData.authType = this.current.jsonData.authType || 'credentials';
  14. this.accessKeyExist = this.current.secureJsonFields.accessKey;
  15. this.secretKeyExist = this.current.secureJsonFields.secretKey;
  16. this.datasourceSrv = datasourceSrv;
  17. this.getRegions();
  18. }
  19. resetAccessKey() {
  20. this.accessKeyExist = false;
  21. }
  22. resetSecretKey() {
  23. this.secretKeyExist = false;
  24. }
  25. authTypes = [
  26. { name: 'Access & secret key', value: 'keys' },
  27. { name: 'Credentials file', value: 'credentials' },
  28. { name: 'ARN', value: 'arn' },
  29. ];
  30. indexPatternTypes: any = [
  31. { name: 'No pattern', value: undefined },
  32. { name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' },
  33. { name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' },
  34. { name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' },
  35. { name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' },
  36. { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
  37. ];
  38. regions = [
  39. 'ap-northeast-1',
  40. 'ap-northeast-2',
  41. 'ap-northeast-3',
  42. 'ap-south-1',
  43. 'ap-southeast-1',
  44. 'ap-southeast-2',
  45. 'ca-central-1',
  46. 'cn-north-1',
  47. 'cn-northwest-1',
  48. 'eu-central-1',
  49. 'eu-north-1',
  50. 'eu-west-1',
  51. 'eu-west-2',
  52. 'eu-west-3',
  53. 'me-south-1',
  54. 'sa-east-1',
  55. 'us-east-1',
  56. 'us-east-2',
  57. 'us-gov-east-1',
  58. 'us-gov-west-1',
  59. 'us-iso-east-1',
  60. 'us-isob-east-1',
  61. 'us-west-1',
  62. 'us-west-2',
  63. ];
  64. getRegions() {
  65. this.datasourceSrv
  66. .loadDatasource(this.current.name)
  67. .then((ds: CloudWatchDatasource) => {
  68. return ds.getRegions();
  69. })
  70. .then(
  71. (regions: any) => {
  72. this.regions = _.map(regions, 'value');
  73. },
  74. (err: any) => {
  75. console.error('failed to get latest regions');
  76. }
  77. );
  78. }
  79. }