grafana/pkg/api/dataproxy.go

34 lines
834 B
Go
Raw Normal View History

package api
import (
"github.com/grafana/grafana/pkg/api/pluginproxy"
2015-02-05 03:37:13 -06:00
"github.com/grafana/grafana/pkg/bus"
"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"
)
2015-10-08 10:30:13 -05:00
func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
query := m.GetDataSourceByIdQuery{Id: id, OrgId: orgId}
if err := bus.Dispatch(&query); err != nil {
2015-10-08 10:30:13 -05:00
return nil, err
}
return query.Result, nil
2015-10-08 10:30:13 -05:00
}
func ProxyDataSourceRequest(c *middleware.Context) {
c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
2015-10-08 10:30:13 -05:00
ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId)
2015-10-08 10:30:13 -05:00
if err != nil {
c.JsonApiErr(500, "Unable to load datasource meta data", err)
return
}
proxyPath := c.Params("*")
proxy := pluginproxy.NewDataSourceProxy(ds, c, proxyPath)
proxy.HandleRequest()
}