HTTP API: grafana /render calls nows with api keys, Fixes #1649

This commit is contained in:
Torkel Ödegaard
2015-04-08 08:59:12 +02:00
parent f28af4f369
commit 059db533d5
8 changed files with 73 additions and 14 deletions
+2 -9
View File
@@ -1,8 +1,6 @@
package renderer
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
"os/exec"
@@ -11,6 +9,7 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
type RenderOpts struct {
@@ -24,7 +23,7 @@ func RenderToPng(params *RenderOpts) (string, error) {
log.Info("PhantomRenderer::renderToPng url %v", params.Url)
binPath, _ := filepath.Abs(filepath.Join(setting.PhantomDir, "phantomjs"))
scriptPath, _ := filepath.Abs(filepath.Join(setting.PhantomDir, "render.js"))
pngPath, _ := filepath.Abs(filepath.Join(setting.ImagesDir, getHash(params.Url)))
pngPath, _ := filepath.Abs(filepath.Join(setting.ImagesDir, util.GetRandomString(20)))
pngPath = pngPath + ".png"
cmd := exec.Command(binPath, scriptPath, "url="+params.Url, "width="+params.Width,
@@ -64,9 +63,3 @@ func RenderToPng(params *RenderOpts) (string, error) {
return pngPath, nil
}
func getHash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}