mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 15:02:28 +08:00
API: Recognize MSSQL data source URLs (#25629)
* API: Recognize MSSQL URLs Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Move MSSQL URL validation into mssql package Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@ -9,12 +9,15 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/datasource"
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/datasource/wrapper"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
var datasourcesLogger = log.New("datasources")
|
||||
|
||||
func GetDataSources(c *models.ReqContext) Response {
|
||||
query := models.GetDataSourcesQuery{OrgId: c.OrgId}
|
||||
|
||||
@ -127,9 +130,11 @@ func DeleteDataSourceByName(c *models.ReqContext) Response {
|
||||
return Success("Data source deleted")
|
||||
}
|
||||
|
||||
func validateURL(u string) Response {
|
||||
func validateURL(tp string, u string) Response {
|
||||
if u != "" {
|
||||
if _, err := datasource.ValidateURL(u); err != nil {
|
||||
if _, err := datasource.ValidateURL(tp, u); err != nil {
|
||||
datasourcesLogger.Error("Received invalid data source URL as part of data source command",
|
||||
"url", u)
|
||||
return Error(400, fmt.Sprintf("Validation error, invalid URL: %q", u), err)
|
||||
}
|
||||
}
|
||||
@ -138,8 +143,9 @@ func validateURL(u string) Response {
|
||||
}
|
||||
|
||||
func AddDataSource(c *models.ReqContext, cmd models.AddDataSourceCommand) Response {
|
||||
datasourcesLogger.Debug("Received command to add data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgId
|
||||
if resp := validateURL(cmd.Url); resp != nil {
|
||||
if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
|
||||
return resp
|
||||
}
|
||||
|
||||
@ -161,9 +167,10 @@ func AddDataSource(c *models.ReqContext, cmd models.AddDataSourceCommand) Respon
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *models.ReqContext, cmd models.UpdateDataSourceCommand) Response {
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.Id = c.ParamsInt64(":id")
|
||||
if resp := validateURL(cmd.Url); resp != nil {
|
||||
if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
|
||||
return resp
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user