Commit a7c816c6 by Torkel Ödegaard

Datasource proxy, switch to lookup by id

parent a2a0e039
...@@ -33,7 +33,7 @@ func Register(m *macaron.Macaron) { ...@@ -33,7 +33,7 @@ func Register(m *macaron.Macaron) {
m.Delete("/api/admin/datasources/:id", auth, DeleteDataSource) m.Delete("/api/admin/datasources/:id", auth, DeleteDataSource)
// data source proxy // data source proxy
m.Any("/api/datasources/proxy/:name/*", auth, ProxyDataSourceRequest) m.Any("/api/datasources/proxy/:id/*", auth, ProxyDataSourceRequest)
// user register // user register
m.Get("/register/*_", Index) m.Get("/register/*_", Index)
......
...@@ -2,6 +2,7 @@ package api ...@@ -2,6 +2,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"strconv"
"strings" "strings"
"github.com/torkelo/grafana-pro/pkg/bus" "github.com/torkelo/grafana-pro/pkg/bus"
...@@ -27,7 +28,7 @@ func renderConfig(data *configJsTmplModel) string { ...@@ -27,7 +28,7 @@ func renderConfig(data *configJsTmplModel) string {
for _, ds := range data.DataSources { for _, ds := range data.DataSources {
url := ds.Url url := ds.Url
if ds.Access == m.DS_ACCESS_PROXY { 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{}{ datasources[ds.Name] = map[string]interface{}{
"type": ds.Type, "type": ds.Type,
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"strings" "strings"
"github.com/torkelo/grafana-pro/pkg/bus" "github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/log"
"github.com/torkelo/grafana-pro/pkg/middleware" "github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models" m "github.com/torkelo/grafana-pro/pkg/models"
) )
...@@ -36,18 +35,17 @@ func NewReverseProxy(target *url.URL, proxyPath string) *httputil.ReverseProxy { ...@@ -36,18 +35,17 @@ func NewReverseProxy(target *url.URL, proxyPath string) *httputil.ReverseProxy {
} else { } else {
req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery
} }
log.Info("Proxy: %v", req.URL.Path)
} }
return &httputil.ReverseProxy{Director: director} return &httputil.ReverseProxy{Director: director}
} }
// TODO: need to cache datasources // TODO: need to cache datasources
func ProxyDataSourceRequest(c *middleware.Context) { func ProxyDataSourceRequest(c *middleware.Context) {
name := c.Params(":name") id := c.ParamsInt64(":id")
query := m.GetDataSourceByNameQuery{ query := m.GetDataSourceByIdQuery{
Name: name, Id: id,
AccountId: c.GetAccountId(), AccountId: c.GetAccountId(),
} }
......
...@@ -42,8 +42,8 @@ type GetDataSourcesQuery struct { ...@@ -42,8 +42,8 @@ type GetDataSourcesQuery struct {
Result []*DataSource Result []*DataSource
} }
type GetDataSourceByNameQuery struct { type GetDataSourceByIdQuery struct {
Name string Id int64
AccountId int64 AccountId int64
Result DataSource Result DataSource
} }
......
...@@ -14,11 +14,11 @@ func init() { ...@@ -14,11 +14,11 @@ func init() {
bus.AddHandler("sql", AddDataSource) bus.AddHandler("sql", AddDataSource)
bus.AddHandler("sql", DeleteDataSource) bus.AddHandler("sql", DeleteDataSource)
bus.AddHandler("sql", UpdateDataSource) bus.AddHandler("sql", UpdateDataSource)
bus.AddHandler("sql", GetDataSourceByName) bus.AddHandler("sql", GetDataSourceById)
} }
func GetDataSourceByName(query *m.GetDataSourceByNameQuery) error { func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
sess := x.Limit(100, 0).Where("account_id=? AND name=?", query.AccountId, query.Name) sess := x.Limit(100, 0).Where("account_id=? AND id=?", query.AccountId, query.Id)
has, err := sess.Get(&query.Result) has, err := sess.Get(&query.Result)
if !has { if !has {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment