mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 04:34:23 -06:00
3c3cf2eee9
* fix(catalog): prefer rendering installed version over latest version * feat(catalog): signify installed version in version history * feat(catalog): introduce installedVersion and latestVersion * refactor(catalog): use latestVersion for installation, simplify plugindetails header logic * refactor(catalog): clean up installedVersion and latestVersion * feat(catalog): use table-layout so versions list table has consistent column widths * test(catalog): update failing tests * removed the need of having a latest version in the plugin catalog type root level. * fixed flaky test depending on what locale it was being running with. * added missing test to verify version for a remote plugin. * fixed version in header. * preventing the UI from break if no versions are available. * fixed failing test due to missing mock data. * added todo as a reminder. * refactor(catalog): prefer grafana plugin icons over gcom notfound images * refactor(Plugins/Admin): change constant name * refactor(Plugins/Admin): add comment to make condition easier to understand * chore: update go modules * feat(Backend/Plugins): add "dependencies" field to `PluginListItem` * feat(Plugins/Admin): show the grafana dependency for the installed version * refactor(Plugins/Admin): use the local version of links * refactor(Plugins/Admin): prefer the local version for `.type` * refactor(Plugins/ADmin): prefer the local `.description` field * fix(Plugins/Admin): fix tests * test(plugins/api): update the expected response for the `api/plugins` tests * chore(Plugins/Admin): add todo comments to check preferation of remote/local values * feat(backend/api): always send the grafana version as a header when proxying to GCOM * feat(plugins/admin): use the `isCompatible` flag to get the latest compatible version * feat(plugins/admin): show the latest compatible version in the versions list * fix(plugins/admin): show the grafana dependency for the latest compatible version * fix(plugins/admin): update the version list when installing/uninstalling a plugin * test(plugins/admin): add some test-cases for the latest-compatible-version * fix(plugins/admin): show the grafana dependency for the installed version (if installed) * feat(plugins/backend): add the `dependencies.grafanaDependency` property to the plugin object * test(plugins/backend): fix tests by adjusting expected response json Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com> Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
var grafanaComProxyTransport = &http.Transport{
|
|
Proxy: http.ProxyFromEnvironment,
|
|
Dial: (&net.Dialer{
|
|
Timeout: 30 * time.Second,
|
|
KeepAlive: 30 * time.Second,
|
|
}).Dial,
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
|
}
|
|
|
|
func ReverseProxyGnetReq(proxyPath string, version string) *httputil.ReverseProxy {
|
|
url, _ := url.Parse(setting.GrafanaComUrl)
|
|
|
|
director := func(req *http.Request) {
|
|
req.URL.Scheme = url.Scheme
|
|
req.URL.Host = url.Host
|
|
req.Host = url.Host
|
|
|
|
req.URL.Path = util.JoinURLFragments(url.Path+"/api", proxyPath)
|
|
|
|
// clear cookie headers
|
|
req.Header.Del("Cookie")
|
|
req.Header.Del("Set-Cookie")
|
|
req.Header.Del("Authorization")
|
|
|
|
// send the current Grafana version for each request proxied to GCOM
|
|
req.Header.Add("grafana-version", version)
|
|
}
|
|
|
|
return &httputil.ReverseProxy{Director: director}
|
|
}
|
|
|
|
func (hs *HTTPServer) ProxyGnetRequest(c *models.ReqContext) {
|
|
proxyPath := web.Params(c.Req)["*"]
|
|
proxy := ReverseProxyGnetReq(proxyPath, hs.Cfg.BuildVersion)
|
|
proxy.Transport = grafanaComProxyTransport
|
|
proxy.ServeHTTP(c.Resp, c.Req)
|
|
c.Resp.Header().Del("Set-Cookie")
|
|
}
|