DataSourceProxy: Handle URL parsing error (#23731)

* pluginproxy: Handle URL parsing error
* pkg/api: Validate data source URLs
* pkg/api: Return 400 for URL validation error
This commit is contained in:
Arve Knudsen
2020-04-22 10:30:06 +02:00
committed by GitHub
parent c3e3067cf4
commit 7d88018531
4 changed files with 115 additions and 27 deletions
+12 -1
View File
@@ -1,6 +1,9 @@
package api
import (
"errors"
"fmt"
"github.com/grafana/grafana/pkg/api/pluginproxy"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models"
@@ -32,7 +35,15 @@ func (hs *HTTPServer) ProxyDataSourceRequest(c *models.ReqContext) {
// macaron does not include trailing slashes when resolving a wildcard path
proxyPath := ensureProxyPathTrailingSlash(c.Req.URL.Path, c.Params("*"))
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath, hs.Cfg)
proxy, err := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath, hs.Cfg)
if err != nil {
if errors.Is(err, pluginproxy.URLValidationError{}) {
c.JsonApiErr(400, fmt.Sprintf("Invalid data source URL: %q", ds.Url), err)
} else {
c.JsonApiErr(500, "Failed creating data source proxy", err)
}
return
}
proxy.HandleRequest()
}