mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 16:12:14 +08:00
Data sources: Don't fail if URL doesn't specify protocol (#24497)
This commit is contained in:
@ -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{
|
||||
|
Reference in New Issue
Block a user