2014-12-29 06:36:08 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2017-08-22 10:14:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/api/pluginproxy"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2016-06-03 02:17:36 -05:00
|
|
|
"github.com/grafana/grafana/pkg/metrics"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2017-01-16 05:16:41 -06:00
|
|
|
)
|
|
|
|
|
2015-10-08 10:30:13 -05:00
|
|
|
func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
|
|
|
|
query := m.GetDataSourceByIdQuery{Id: id, OrgId: orgId}
|
2015-03-11 11:34:11 -05:00
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
2015-10-08 10:30:13 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-06-06 10:11:46 -05:00
|
|
|
return query.Result, nil
|
2015-10-08 10:30:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ProxyDataSourceRequest(c *middleware.Context) {
|
2016-06-03 02:17:36 -05:00
|
|
|
c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
|
|
|
|
|
2015-10-08 10:30:13 -05:00
|
|
|
ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId)
|
2016-06-03 02:17:36 -05:00
|
|
|
|
2015-10-08 10:30:13 -05:00
|
|
|
if err != nil {
|
2014-12-29 06:36:08 -06:00
|
|
|
c.JsonApiErr(500, "Unable to load datasource meta data", err)
|
2015-03-11 11:34:11 -05:00
|
|
|
return
|
2014-12-29 06:36:08 -06:00
|
|
|
}
|
|
|
|
|
2016-07-22 06:15:18 -05:00
|
|
|
proxyPath := c.Params("*")
|
2017-08-22 10:14:15 -05:00
|
|
|
proxy := pluginproxy.NewDataSourceProxy(ds, c, proxyPath)
|
|
|
|
proxy.HandleRequest()
|
2016-08-17 00:33:59 -05:00
|
|
|
}
|