From bd4e3f0d169093d8b4d7dfddcaac40f9e3e35d86 Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Wed, 25 Jan 2023 13:23:18 +0000 Subject: [PATCH] API: Correctly use new grafana_com.api_url setting in /api/gnet proxy (#60893) During the review of the initial PR adding this (#59506) I removed a new global variable from the setting package, but forgot to update the reference to the new setting, so the API URL wasn't actually being used. This PR updates the proxy endpoint to use the API URL correctly. Aside: I'm not a huge fan of how the error is being ignored when parsing the URL, but I think that should be addressed in a separate PR if anyone has a suggestion for how we should handle it. (Should we check that the URL is valid when parsing config?) --- pkg/api/grafana_com_proxy.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/api/grafana_com_proxy.go b/pkg/api/grafana_com_proxy.go index db974883d49..ca9cf6a71bb 100644 --- a/pkg/api/grafana_com_proxy.go +++ b/pkg/api/grafana_com_proxy.go @@ -9,7 +9,6 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/models" - "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util/proxyutil" "github.com/grafana/grafana/pkg/web" @@ -24,8 +23,8 @@ var grafanaComProxyTransport = &http.Transport{ TLSHandshakeTimeout: 10 * time.Second, } -func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string) *httputil.ReverseProxy { - url, _ := url.Parse(setting.GrafanaComUrl) +func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string, grafanaComUrl string) *httputil.ReverseProxy { + url, _ := url.Parse(grafanaComUrl) director := func(req *http.Request) { req.URL.Scheme = url.Scheme @@ -48,7 +47,7 @@ func ReverseProxyGnetReq(logger log.Logger, proxyPath string, version string) *h func (hs *HTTPServer) ProxyGnetRequest(c *models.ReqContext) { proxyPath := web.Params(c.Req)["*"] - proxy := ReverseProxyGnetReq(c.Logger, proxyPath, hs.Cfg.BuildVersion) + proxy := ReverseProxyGnetReq(c.Logger, proxyPath, hs.Cfg.BuildVersion, hs.Cfg.GrafanaComAPIURL) proxy.Transport = grafanaComProxyTransport proxy.ServeHTTP(c.Resp, c.Req) }