mirror of https://github.com/grafana/grafana.git
Solo panel and phantom rendering work
This commit is contained in:
parent
b499bdea3b
commit
4a73e2d0e9
|
|
@ -1,10 +1,12 @@
|
|||
var page = require('webpage').create();
|
||||
var args = require('system').args;
|
||||
var params = {};
|
||||
var regexp = /^([^=]+)=([^$]+)/;
|
||||
|
||||
args.forEach(function(arg) {
|
||||
var parts = arg.split('=');
|
||||
params[parts[0]] = parts[1];
|
||||
var parts = arg.match(regexp);
|
||||
if (!parts) { return; }
|
||||
params[parts[1]] = parts[2];
|
||||
});
|
||||
|
||||
var usage = "url=<url> png=<filename> width=<width> height=<height>";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/sessions"
|
||||
)
|
||||
|
||||
type authContext struct {
|
||||
|
|
@ -19,16 +24,34 @@ func (self *HttpServer) authDenied(c *gin.Context) {
|
|||
c.Abort(302)
|
||||
}
|
||||
|
||||
func authGetRequestAccountId(c *gin.Context, session *sessions.Session) (int, error) {
|
||||
accountId := session.Values["accountId"]
|
||||
|
||||
urlQuery := c.Request.URL.Query()
|
||||
if len(urlQuery["render"]) > 0 {
|
||||
accId, _ := strconv.Atoi(urlQuery["accountId"][0])
|
||||
session.Values["accountId"] = accId
|
||||
accountId = accId
|
||||
}
|
||||
|
||||
if accountId == nil {
|
||||
return -1, errors.New("Auth: session account id not found")
|
||||
}
|
||||
|
||||
return accountId.(int), nil
|
||||
}
|
||||
|
||||
func (self *HttpServer) auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
session, _ := sessionStore.Get(c.Request, "grafana-session")
|
||||
accountId, err := authGetRequestAccountId(c, session)
|
||||
|
||||
if c.Request.URL.Path != "/login" && session.Values["accountId"] == nil {
|
||||
if err != nil && c.Request.URL.Path != "/login" {
|
||||
self.authDenied(c)
|
||||
return
|
||||
}
|
||||
|
||||
account, err := self.store.GetAccount(session.Values["accountId"].(int))
|
||||
account, err := self.store.GetAccount(accountId)
|
||||
if err != nil {
|
||||
self.authDenied(c)
|
||||
return
|
||||
|
|
@ -42,7 +65,6 @@ func (self *HttpServer) auth() gin.HandlerFunc {
|
|||
|
||||
c.Set("userAccount", account)
|
||||
c.Set("usingAccount", usingAccount)
|
||||
|
||||
session.Save(c.Request, c.Writer)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,24 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
log "github.com/alecthomas/log4go"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
addRoutes(func(self *HttpServer) {
|
||||
self.router.GET("/api/render/*url", self.renderToPng)
|
||||
self.addRoute("GET", "/api/render/*url", self.renderToPng)
|
||||
})
|
||||
}
|
||||
|
||||
func (self *HttpServer) renderToPng(c *gin.Context) {
|
||||
func (self *HttpServer) renderToPng(c *gin.Context, auth *authContext) {
|
||||
url := c.Params.ByName("url")
|
||||
accountId := auth.getAccountId()
|
||||
|
||||
log.Info("Rendering url %v", url)
|
||||
pngPath, err := self.renderer.RenderToPng("http://localhost:3000/" + url)
|
||||
pngPath, err := self.renderer.RenderToPng("http://localhost:3000" + url + "?render&accountId=" + strconv.Itoa(accountId))
|
||||
if err != nil {
|
||||
c.HTML(500, "error.html", nil)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue