Data sources: Don't fail if URL doesn't specify protocol (#24497)

This commit is contained in:
Arve Knudsen
2020-05-12 13:04:18 +02:00
committed by GitHub
parent 0475f96347
commit 164242f5fd
7 changed files with 193 additions and 25 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/opentracing/opentracing-go"
"golang.org/x/oauth2"
"github.com/grafana/grafana/pkg/api/datasource"
"github.com/grafana/grafana/pkg/bus"
glog "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/login/social"
@ -31,20 +32,6 @@ var (
client = newHTTPClient()
)
type URLValidationError struct {
error
url string
}
func (e URLValidationError) Error() string {
return fmt.Sprintf("Validation of URL %q failed: %s", e.url, e.error.Error())
}
func (e URLValidationError) Unwrap() error {
return e.error
}
type DataSourceProxy struct {
ds *models.DataSource
ctx *models.ReqContext
@ -86,9 +73,9 @@ func (lw *logWrapper) Write(p []byte) (n int, err error) {
// NewDataSourceProxy creates a new Datasource proxy
func NewDataSourceProxy(ds *models.DataSource, plugin *plugins.DataSourcePlugin, ctx *models.ReqContext,
proxyPath string, cfg *setting.Cfg) (*DataSourceProxy, error) {
targetURL, err := url.Parse(ds.Url)
targetURL, err := datasource.ValidateURL(ds.Url)
if err != nil {
return nil, URLValidationError{error: err, url: ds.Url}
return nil, err
}
return &DataSourceProxy{