Skip to content

Commit 205d423

Browse files
committed
feat(cloudwatch): only support proxy mode, can remove frontend aws-sdk lib
1 parent 3c6a06a commit 205d423

File tree

14 files changed

+86
-11623
lines changed

14 files changed

+86
-11623
lines changed

bower.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"angular-native-dragdrop": "~1.1.1",
2222
"angular-bindonce": "~0.3.3",
2323
"requirejs": "~2.1.18",
24-
"requirejs-text": "~2.0.14",
25-
"aws-sdk": "~2.1.42"
24+
"requirejs-text": "~2.0.14"
2625
}
2726
}

public/app/plugins/datasource/cloudwatch/datasource.js

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* global AWS */
21
define([
32
'angular',
43
'lodash',
54
'moment',
65
'./queryCtrl',
76
'./directives',
8-
'aws-sdk',
97
],
108
function (angular, _) {
119
'use strict';
@@ -18,14 +16,8 @@ function (angular, _) {
1816
this.type = 'cloudwatch';
1917
this.name = datasource.name;
2018
this.supportMetrics = true;
21-
this.proxyMode = (datasource.jsonData.access === 'proxy');
2219
this.proxyUrl = datasource.url;
23-
2420
this.defaultRegion = datasource.jsonData.defaultRegion;
25-
this.credentials = {
26-
accessKeyId: datasource.jsonData.accessKeyId,
27-
secretAccessKey: datasource.jsonData.secretAccessKey
28-
};
2921

3022
/* jshint -W101 */
3123
this.supportedRegion = [
@@ -302,6 +294,7 @@ function (angular, _) {
302294
};
303295

304296
CloudWatchDatasource.prototype.performSuggestNamespace = function() {
297+
console.log(this.supportMetrics);
305298
return _.keys(this.supportedMetrics);
306299
};
307300

@@ -493,53 +486,42 @@ function (angular, _) {
493486
};
494487

495488
CloudWatchDatasource.prototype.getAwsClient = function(region, service) {
496-
if (!this.proxyMode) {
497-
return new AWS[service]({
498-
region: region,
499-
accessKeyId: this.credentials.accessKeyId,
500-
secretAccessKey: this.credentials.secretAccessKey
501-
});
502-
} else {
503-
var self = this;
504-
var generateRequestProxy = function(service, action) {
505-
return function(params, callback) {
506-
var data = {
507-
region: region,
508-
service: service,
509-
action: action,
510-
parameters: params
511-
};
512-
513-
var options = {
514-
method: 'POST',
515-
url: self.proxyUrl,
516-
data: data
517-
};
518-
519-
$http(options).then(function(response) {
520-
callback(null, response.data);
521-
}, function(err) {
522-
callback(err, []);
523-
});
489+
var self = this;
490+
var generateRequestProxy = function(service, action) {
491+
return function(params, callback) {
492+
var data = {
493+
region: region,
494+
service: service,
495+
action: action,
496+
parameters: params
497+
};
498+
499+
var options = {
500+
method: 'POST',
501+
url: self.proxyUrl,
502+
data: data
524503
};
504+
505+
$http(options).then(function(response) {
506+
callback(null, response.data);
507+
}, function(err) {
508+
callback(err, []);
509+
});
525510
};
511+
};
526512

527-
var proxy;
528-
switch (service) {
529-
case 'CloudWatch':
530-
proxy = {
513+
switch (service) {
514+
case 'CloudWatch': {
515+
return {
531516
getMetricStatistics: generateRequestProxy('CloudWatch', 'GetMetricStatistics'),
532517
listMetrics: generateRequestProxy('CloudWatch', 'ListMetrics')
533518
};
534-
break;
535-
case 'EC2':
536-
proxy = {
519+
}
520+
case 'EC2': {
521+
return {
537522
describeInstances: generateRequestProxy('EC2', 'DescribeInstances')
538523
};
539-
break;
540524
}
541-
542-
return proxy;
543525
}
544526
};
545527

public/app/plugins/datasource/cloudwatch/partials/config.html

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,53 @@ <h5>CloudWatch details</h5>
99
<input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.defaultRegion' placeholder="" required></input>
1010
</li>
1111
</ul>
12-
<ul class="tight-form-list">
13-
<li class="tight-form-item">
14-
Access <tip>Direct = url is used directly from browser, Proxy = Grafana backend will proxy the request</label>
15-
</li>
16-
<li>
17-
<select class="input-small tight-form-input" ng-model="current.jsonData.access" ng-options="f for f in ['direct', 'proxy']" ng-init="current.jsonData.access = current.jsonData.access || 'direct'"></select>
18-
</li>
19-
</ul>
20-
<div class="clearfix"></div>
21-
</div>
22-
<div class="tight-form" ng-show="current.jsonData.access === 'direct'">
23-
<ul class="tight-form-list">
24-
<li class="tight-form-item" style="width: 160px">
25-
Access Key Id
26-
</li>
27-
<li>
28-
<input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.accessKeyId' placeholder="" ng-required="current.jsonData.access === 'direct'"></input>
29-
</li>
30-
</ul>
31-
<div class="clearfix"></div>
32-
</div>
33-
<div class="tight-form" ng-show="current.jsonData.access === 'direct'">
34-
<ul class="tight-form-list">
35-
<li class="tight-form-item" style="width: 160px">
36-
Secret Access Key
37-
</li>
38-
<li>
39-
<input type="password" class="tight-form-input input-xlarge" ng-model='current.jsonData.secretAccessKey' placeholder="" ng-required="current.jsonData.access === 'direct'"></input>
40-
</li>
41-
</ul>
42-
<div class="clearfix"></div>
43-
</div>
44-
<div class="tight-form last">
45-
<ul class="tight-form-list">
46-
<li class="tight-form-item" style="width: 160px">
47-
Custom Metric Attributes
48-
</li>
49-
<li>
50-
<input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.customMetricsAttributes[0]' ng-init="current.jsonData.customMetricsAttributes = current.jsonData.customMetricsAttributes || []" placeholder="JSON url" bs-tooltip="'Set JSON url of the result, \'aws cloudwatch list-metrics --output json\''"></input>
51-
</li>
52-
</ul>
5312
<div class="clearfix"></div>
5413
</div>
14+
15+
<!-- <div class="tight&#45;form" ng&#45;show="current.jsonData.access === 'direct'"> -->
16+
<!-- <ul class="tight&#45;form&#45;list"> -->
17+
<!-- <li class="tight&#45;form&#45;item" style="width: 160px"> -->
18+
<!-- </li> -->
19+
<!-- <li> -->
20+
<!-- <input type="text" class="tight&#45;form&#45;input input&#45;xlarge" ng&#45;model='current.jsonData.accessKeyId' placeholder=""></input> -->
21+
<!-- </li> -->
22+
<!-- </ul> -->
23+
<!-- <div class="clearfix"></div> -->
24+
<!-- </div> -->
25+
<!-- <div class="tight&#45;form" ng&#45;show="current.jsonData.access === 'direct'"> -->
26+
<!-- <ul class="tight&#45;form&#45;list"> -->
27+
<!-- <li class="tight&#45;form&#45;item" style="width: 160px"> -->
28+
<!-- Access Key Id -->
29+
<!-- </li> -->
30+
<!-- <li> -->
31+
<!-- <input type="text" class="tight&#45;form&#45;input input&#45;xlarge" ng&#45;model='current.jsonData.accessKeyId' placeholder=""></input> -->
32+
<!-- </li> -->
33+
<!-- </ul> -->
34+
<!-- <div class="clearfix"></div> -->
35+
<!-- </div> -->
36+
<!-- <div class="tight&#45;form" ng&#45;show="current.jsonData.access === 'direct'"> -->
37+
<!-- <ul class="tight&#45;form&#45;list"> -->
38+
<!-- <li class="tight&#45;form&#45;item" style="width: 160px"> -->
39+
<!-- Secret Access Key -->
40+
<!-- </li> -->
41+
<!-- <li> -->
42+
<!-- <input type="password" class="tight&#45;form&#45;input input&#45;xlarge" ng&#45;model='current.jsonData.secretAccessKey' placeholder=""></input> -->
43+
<!-- </li> -->
44+
<!-- </ul> -->
45+
<!-- <div class="clearfix"></div> -->
46+
<!-- </div> -->
47+
48+
<!-- <div class="tight&#45;form last"> -->
49+
<!-- <ul class="tight&#45;form&#45;list"> -->
50+
<!-- <li class="tight&#45;form&#45;item" style="width: 160px"> -->
51+
<!-- Custom Metric Attributes -->
52+
<!-- </li> -->
53+
<!-- <li> -->
54+
<!-- <input type="text" class="tight&#45;form&#45;input input&#45;xlarge" -->
55+
<!-- ng&#45;model='current.jsonData.customMetricsAttributes[0]' -->
56+
<!-- ng&#45;init="current.jsonData.customMetricsAttributes = current.jsonData.customMetricsAttributes || []" placeholder="JSON url" bs&#45;tooltip="'Set JSON url of the result, \'aws cloudwatch list&#45;metrics &#45;&#45;output json\''"> -->
57+
<!-- </input> -->
58+
<!-- </li> -->
59+
<!-- </ul> -->
60+
<!-- <div class="clearfix"></div> -->
61+
<!-- </div> -->

public/vendor/aws-sdk/.bower.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

public/vendor/aws-sdk/CONTRIBUTING.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)