mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 16:32:15 +08:00
Datasource proxy, switch to lookup by id
This commit is contained in:
@ -33,7 +33,7 @@ func Register(m *macaron.Macaron) {
|
||||
m.Delete("/api/admin/datasources/:id", auth, DeleteDataSource)
|
||||
|
||||
// data source proxy
|
||||
m.Any("/api/datasources/proxy/:name/*", auth, ProxyDataSourceRequest)
|
||||
m.Any("/api/datasources/proxy/:id/*", auth, ProxyDataSourceRequest)
|
||||
|
||||
// user register
|
||||
m.Get("/register/*_", Index)
|
||||
|
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
@ -27,7 +28,7 @@ func renderConfig(data *configJsTmplModel) string {
|
||||
for _, ds := range data.DataSources {
|
||||
url := ds.Url
|
||||
if ds.Access == m.DS_ACCESS_PROXY {
|
||||
url = "/api/datasources/proxy/" + ds.Name
|
||||
url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10)
|
||||
}
|
||||
datasources[ds.Name] = map[string]interface{}{
|
||||
"type": ds.Type,
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/log"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
)
|
||||
@ -36,18 +35,17 @@ func NewReverseProxy(target *url.URL, proxyPath string) *httputil.ReverseProxy {
|
||||
} else {
|
||||
req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery
|
||||
}
|
||||
|
||||
log.Info("Proxy: %v", req.URL.Path)
|
||||
}
|
||||
|
||||
return &httputil.ReverseProxy{Director: director}
|
||||
}
|
||||
|
||||
// TODO: need to cache datasources
|
||||
func ProxyDataSourceRequest(c *middleware.Context) {
|
||||
name := c.Params(":name")
|
||||
id := c.ParamsInt64(":id")
|
||||
|
||||
query := m.GetDataSourceByNameQuery{
|
||||
Name: name,
|
||||
query := m.GetDataSourceByIdQuery{
|
||||
Id: id,
|
||||
AccountId: c.GetAccountId(),
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ type GetDataSourcesQuery struct {
|
||||
Result []*DataSource
|
||||
}
|
||||
|
||||
type GetDataSourceByNameQuery struct {
|
||||
Name string
|
||||
type GetDataSourceByIdQuery struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
Result DataSource
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ func init() {
|
||||
bus.AddHandler("sql", AddDataSource)
|
||||
bus.AddHandler("sql", DeleteDataSource)
|
||||
bus.AddHandler("sql", UpdateDataSource)
|
||||
bus.AddHandler("sql", GetDataSourceByName)
|
||||
bus.AddHandler("sql", GetDataSourceById)
|
||||
}
|
||||
|
||||
func GetDataSourceByName(query *m.GetDataSourceByNameQuery) error {
|
||||
sess := x.Limit(100, 0).Where("account_id=? AND name=?", query.AccountId, query.Name)
|
||||
func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
|
||||
sess := x.Limit(100, 0).Where("account_id=? AND id=?", query.AccountId, query.Id)
|
||||
has, err := sess.Get(&query.Result)
|
||||
|
||||
if !has {
|
||||
|
Reference in New Issue
Block a user