refer to plugins are ExternalPlugin instead of thirdParty
This commit is contained in:
+1
-1
@@ -185,7 +185,7 @@ func Register(r *macaron.Macaron) {
|
||||
// rendering
|
||||
r.Get("/render/*", reqSignedIn, RenderToPng)
|
||||
|
||||
InitThirdPartyRoutes(r)
|
||||
InitExternalPluginRoutes(r)
|
||||
|
||||
r.NotFound(NotFoundHandler)
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/Unknwon/macaron"
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func InitThirdPartyRoutes(r *macaron.Macaron) {
|
||||
func InitExternalPluginRoutes(r *macaron.Macaron) {
|
||||
/*
|
||||
// Handle Auth and role requirements
|
||||
if route.ReqSignedIn {
|
||||
@@ -30,34 +30,33 @@ func InitThirdPartyRoutes(r *macaron.Macaron) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
for _, integration := range plugins.Integrations {
|
||||
log.Printf("adding routes for integration")
|
||||
for _, route := range integration.Routes {
|
||||
log.Printf("adding route %s %s", route.Method, route.Path)
|
||||
r.Route(util.JoinUrlFragments("/thirdparty/", route.Path), route.Method, ThirdParty(route.Url))
|
||||
for _, plugin := range plugins.ExternalPlugins {
|
||||
log.Info("adding routes for external plugin")
|
||||
for _, route := range plugin.Settings.Routes {
|
||||
log.Info("adding route %s /plugins%s", route.Method, route.Path)
|
||||
r.Route(util.JoinUrlFragments("/plugins/", route.Path), route.Method, ExternalPlugin(route.Url))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ThirdParty(routeUrl string) macaron.Handler {
|
||||
func ExternalPlugin(routeUrl string) macaron.Handler {
|
||||
return func(c *middleware.Context) {
|
||||
path := c.Params("*")
|
||||
|
||||
//Create a HTTP header with the context in it.
|
||||
ctx, err := json.Marshal(c.SignedInUser)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Not found", err)
|
||||
c.JsonApiErr(500, "failed to marshal context to json.", err)
|
||||
return
|
||||
}
|
||||
log.Printf(string(ctx))
|
||||
targetUrl, _ := url.Parse(routeUrl)
|
||||
proxy := NewThirdPartyProxy(string(ctx), path, targetUrl)
|
||||
proxy := NewExternalPluginProxy(string(ctx), path, targetUrl)
|
||||
proxy.Transport = dataProxyTransport
|
||||
proxy.ServeHTTP(c.RW(), c.Req.Request)
|
||||
}
|
||||
}
|
||||
|
||||
func NewThirdPartyProxy(ctx string, proxyPath string, targetUrl *url.URL) *httputil.ReverseProxy {
|
||||
func NewExternalPluginProxy(ctx string, proxyPath string, targetUrl *url.URL) *httputil.ReverseProxy {
|
||||
director := func(req *http.Request) {
|
||||
req.URL.Scheme = targetUrl.Scheme
|
||||
req.URL.Host = targetUrl.Host
|
||||
+14
-14
@@ -52,25 +52,25 @@ func setIndexViewData(c *middleware.Context) error {
|
||||
if setting.GoogleTagManagerId != "" {
|
||||
c.Data["GoogleTagManagerId"] = setting.GoogleTagManagerId
|
||||
}
|
||||
// This can be loaded from the DB/file to allow 3rdParty integration
|
||||
thirdPartyJs := make([]string, 0)
|
||||
thirdPartyCss := make([]string, 0)
|
||||
thirdPartyMenu := make([]*plugins.ThirdPartyMenuItem, 0)
|
||||
for _, integration := range plugins.Integrations {
|
||||
for _, js := range integration.Js {
|
||||
thirdPartyJs = append(thirdPartyJs, js.Src)
|
||||
|
||||
externalPluginJs := make([]string, 0)
|
||||
externalPluginCss := make([]string, 0)
|
||||
externalPluginMenu := make([]*plugins.ExternalPluginMenuItem, 0)
|
||||
for _, plugin := range plugins.ExternalPlugins {
|
||||
for _, js := range plugin.Settings.Js {
|
||||
externalPluginJs = append(externalPluginJs, js.Src)
|
||||
}
|
||||
for _, css := range integration.Css {
|
||||
thirdPartyCss = append(thirdPartyCss, css.Href)
|
||||
for _, css := range plugin.Settings.Css {
|
||||
externalPluginCss = append(externalPluginCss, css.Href)
|
||||
}
|
||||
for _, item := range integration.MenuItems {
|
||||
thirdPartyMenu = append(thirdPartyMenu, item)
|
||||
for _, item := range plugin.Settings.MenuItems {
|
||||
externalPluginMenu = append(externalPluginMenu, item)
|
||||
}
|
||||
|
||||
}
|
||||
c.Data["ThirdPartyJs"] = thirdPartyJs
|
||||
c.Data["ThirdPartyCss"] = thirdPartyCss
|
||||
c.Data["ThirdPartyMenu"] = thirdPartyMenu
|
||||
c.Data["ExternalPluginJs"] = externalPluginJs
|
||||
c.Data["ExternalPluginCss"] = externalPluginCss
|
||||
c.Data["ExternalPluginMenu"] = externalPluginMenu
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user