Plugins: Add token to gcom requests (#96261)
This commit is contained in:
committed by
GitHub
parent
3b8499eaee
commit
a8174f9285
@@ -23,7 +23,7 @@ var grafanaComProxyTransport = &http.Transport{
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string, grafanaComAPIUrl string) *httputil.ReverseProxy {
|
||||
func ReverseProxyGnetReq(logger log.Logger, proxyPath, version, grafanaComAPIUrl, grafanaComAPIToken string) *httputil.ReverseProxy {
|
||||
url, _ := url.Parse(grafanaComAPIUrl)
|
||||
|
||||
director := func(req *http.Request) {
|
||||
@@ -40,6 +40,10 @@ func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string, gr
|
||||
|
||||
// send the current Grafana version for each request proxied to GCOM
|
||||
req.Header.Add("grafana-version", version)
|
||||
|
||||
if grafanaComAPIToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+grafanaComAPIToken)
|
||||
}
|
||||
}
|
||||
|
||||
return proxyutil.NewReverseProxy(logger, director)
|
||||
@@ -47,7 +51,7 @@ func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string, gr
|
||||
|
||||
func (hs *HTTPServer) ProxyGnetRequest(c *contextmodel.ReqContext) {
|
||||
proxyPath := web.Params(c.Req)["*"]
|
||||
proxy := ReverseProxyGnetReq(c.Logger, proxyPath, hs.Cfg.BuildVersion, hs.Cfg.GrafanaComAPIURL)
|
||||
proxy := ReverseProxyGnetReq(c.Logger, proxyPath, hs.Cfg.BuildVersion, hs.Cfg.GrafanaComAPIURL, hs.Cfg.PluginInstallToken)
|
||||
proxy.Transport = grafanaComProxyTransport
|
||||
proxy.ServeHTTP(c.Resp, c.Req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user