mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactoring: some minor refactoring and changes to AWS profile PR #3053
This commit is contained in:
parent
374fbad06d
commit
5d64568f3e
@ -12,6 +12,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
type actionHandler func(*cwRequest, *middleware.Context)
|
||||
@ -19,10 +20,10 @@ type actionHandler func(*cwRequest, *middleware.Context)
|
||||
var actionHandlers map[string]actionHandler
|
||||
|
||||
type cwRequest struct {
|
||||
Region string `json:"region"`
|
||||
Profile string `json:"profile"`
|
||||
Action string `json:"action"`
|
||||
Body []byte `json:"-"`
|
||||
Region string `json:"region"`
|
||||
Action string `json:"action"`
|
||||
Body []byte `json:"-"`
|
||||
DataSource *m.DataSource
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -41,7 +42,7 @@ func handleGetMetricStatistics(req *cwRequest, c *middleware.Context) {
|
||||
creds := credentials.NewChainCredentials(
|
||||
[]credentials.Provider{
|
||||
&credentials.EnvProvider{},
|
||||
&credentials.SharedCredentialsProvider{Filename: "", Profile: req.Profile},
|
||||
&credentials.SharedCredentialsProvider{Filename: "", Profile: req.DataSource.Database},
|
||||
&ec2rolecreds.EC2RoleProvider{ExpiryWindow: 5 * time.Minute},
|
||||
})
|
||||
svc := cloudwatch.New(&aws.Config{
|
||||
@ -85,7 +86,7 @@ func handleListMetrics(req *cwRequest, c *middleware.Context) {
|
||||
creds := credentials.NewChainCredentials(
|
||||
[]credentials.Provider{
|
||||
&credentials.EnvProvider{},
|
||||
&credentials.SharedCredentialsProvider{Filename: "", Profile: req.Profile},
|
||||
&credentials.SharedCredentialsProvider{Filename: "", Profile: req.DataSource.Database},
|
||||
&ec2rolecreds.EC2RoleProvider{ExpiryWindow: 5 * time.Minute},
|
||||
})
|
||||
svc := cloudwatch.New(&aws.Config{
|
||||
@ -145,9 +146,10 @@ func handleDescribeInstances(req *cwRequest, c *middleware.Context) {
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
|
||||
func HandleRequest(c *middleware.Context) {
|
||||
func HandleRequest(c *middleware.Context, ds *m.DataSource) {
|
||||
var req cwRequest
|
||||
req.Body, _ = ioutil.ReadAll(c.Req.Request.Body)
|
||||
req.DataSource = ds
|
||||
json.Unmarshal(req.Body, &req)
|
||||
|
||||
if handler, found := actionHandlers[req.Action]; !found {
|
||||
|
@ -97,7 +97,7 @@ func ProxyDataSourceRequest(c *middleware.Context) {
|
||||
}
|
||||
|
||||
if ds.Type == m.DS_CLOUDWATCH {
|
||||
cloudwatch.HandleRequest(c)
|
||||
cloudwatch.HandleRequest(c, ds)
|
||||
} else {
|
||||
proxyPath := c.Params("*")
|
||||
proxy := NewReverseProxy(ds, proxyPath, targetUrl)
|
||||
|
@ -18,7 +18,6 @@ function (angular, _) {
|
||||
this.supportMetrics = true;
|
||||
this.proxyUrl = datasource.url;
|
||||
this.defaultRegion = datasource.jsonData.defaultRegion;
|
||||
this.profile = datasource.jsonData.profile;
|
||||
}
|
||||
|
||||
CloudWatchDatasource.prototype.query = function(options) {
|
||||
@ -74,7 +73,6 @@ function (angular, _) {
|
||||
CloudWatchDatasource.prototype.performTimeSeriesQuery = function(query, start, end) {
|
||||
return this.awsRequest({
|
||||
region: query.region,
|
||||
profile: this.profile,
|
||||
action: 'GetMetricStatistics',
|
||||
parameters: {
|
||||
namespace: query.namespace,
|
||||
@ -117,7 +115,6 @@ function (angular, _) {
|
||||
CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensions) {
|
||||
var request = {
|
||||
region: templateSrv.replace(region),
|
||||
profile: this.profile,
|
||||
action: 'ListMetrics',
|
||||
parameters: {
|
||||
namespace: templateSrv.replace(namespace),
|
||||
|
@ -1,73 +1,29 @@
|
||||
<br>
|
||||
<h5>CloudWatch details</h5>
|
||||
|
||||
<div class="tight-form last">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 160px">
|
||||
Default Region<tip>Specify the region, such as for US West (Oregon) use ` us-west-2 ` as the region.</tip>
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.defaultRegion' placeholder="" required></input>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
<div class="editor-row">
|
||||
<div class="section tight-form-container" style="margin-bottom: 20px">
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 200px">
|
||||
Credentials profile name<tip>Credentials profile name, as specified in ~/.aws/credentials, leave blank for default</tip>
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-large last" ng-model='current.database' placeholder="default" required></input>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 200px">
|
||||
Default Region<tip>Specify the region, such as for US West (Oregon) use ` us-west-2 ` as the region.</tip>
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-large last" ng-model='current.jsonData.defaultRegion' placeholder="" required></input>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tight-form last">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 160px">
|
||||
AWS Profile
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.profile' placeholder="default" required></input>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="tight-form" ng-show="current.jsonData.access === 'direct'"> -->
|
||||
<!-- <ul class="tight-form-list"> -->
|
||||
<!-- <li class="tight-form-item" style="width: 160px"> -->
|
||||
<!-- </li> -->
|
||||
<!-- <li> -->
|
||||
<!-- <input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.accessKeyId' placeholder=""></input> -->
|
||||
<!-- </li> -->
|
||||
<!-- </ul> -->
|
||||
<!-- <div class="clearfix"></div> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="tight-form" ng-show="current.jsonData.access === 'direct'"> -->
|
||||
<!-- <ul class="tight-form-list"> -->
|
||||
<!-- <li class="tight-form-item" style="width: 160px"> -->
|
||||
<!-- Access Key Id -->
|
||||
<!-- </li> -->
|
||||
<!-- <li> -->
|
||||
<!-- <input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.accessKeyId' placeholder=""></input> -->
|
||||
<!-- </li> -->
|
||||
<!-- </ul> -->
|
||||
<!-- <div class="clearfix"></div> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="tight-form" ng-show="current.jsonData.access === 'direct'"> -->
|
||||
<!-- <ul class="tight-form-list"> -->
|
||||
<!-- <li class="tight-form-item" style="width: 160px"> -->
|
||||
<!-- Secret Access Key -->
|
||||
<!-- </li> -->
|
||||
<!-- <li> -->
|
||||
<!-- <input type="password" class="tight-form-input input-xlarge" ng-model='current.jsonData.secretAccessKey' placeholder=""></input> -->
|
||||
<!-- </li> -->
|
||||
<!-- </ul> -->
|
||||
<!-- <div class="clearfix"></div> -->
|
||||
<!-- </div> -->
|
||||
|
||||
<!-- <div class="tight-form last"> -->
|
||||
<!-- <ul class="tight-form-list"> -->
|
||||
<!-- <li class="tight-form-item" style="width: 160px"> -->
|
||||
<!-- Custom Metric Attributes -->
|
||||
<!-- </li> -->
|
||||
<!-- <li> -->
|
||||
<!-- <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> -->
|
||||
<!-- </li> -->
|
||||
<!-- </ul> -->
|
||||
<!-- <div class="clearfix"></div> -->
|
||||
<!-- </div> -->
|
||||
|
Loading…
Reference in New Issue
Block a user