mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	Remove Macaron ParamsInt64 function from code base (#43810)
* draft commit * change all calls * Compilation errors
This commit is contained in:
		@@ -7,6 +7,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strconv"
 | 
			
		||||
 | 
			
		||||
	"github.com/grafana/grafana-plugin-sdk-go/backend"
 | 
			
		||||
	"github.com/grafana/grafana/pkg/api/datasource"
 | 
			
		||||
@@ -82,8 +83,12 @@ func (hs *HTTPServer) getDataSourceAccessControlMetadata(c *models.ReqContext, d
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (hs *HTTPServer) GetDataSourceById(c *models.ReqContext) response.Response {
 | 
			
		||||
	id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return response.Error(http.StatusBadRequest, "id is invalid", err)
 | 
			
		||||
	}
 | 
			
		||||
	query := models.GetDataSourceQuery{
 | 
			
		||||
		Id:    c.ParamsInt64(":id"),
 | 
			
		||||
		Id:    id,
 | 
			
		||||
		OrgId: c.OrgId,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -111,7 +116,10 @@ func (hs *HTTPServer) GetDataSourceById(c *models.ReqContext) response.Response
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (hs *HTTPServer) DeleteDataSourceById(c *models.ReqContext) response.Response {
 | 
			
		||||
	id := c.ParamsInt64(":id")
 | 
			
		||||
	id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return response.Error(http.StatusBadRequest, "id is invalid", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if id <= 0 {
 | 
			
		||||
		return response.Error(400, "Missing valid datasource id", nil)
 | 
			
		||||
@@ -279,12 +287,16 @@ func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext) response.Response {
 | 
			
		||||
	}
 | 
			
		||||
	datasourcesLogger.Debug("Received command to update data source", "url", cmd.Url)
 | 
			
		||||
	cmd.OrgId = c.OrgId
 | 
			
		||||
	cmd.Id = c.ParamsInt64(":id")
 | 
			
		||||
	var err error
 | 
			
		||||
	cmd.Id, err = strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return response.Error(http.StatusBadRequest, "id is invalid", err)
 | 
			
		||||
	}
 | 
			
		||||
	if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
 | 
			
		||||
		return resp
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err := hs.fillWithSecureJSONData(c.Req.Context(), &cmd)
 | 
			
		||||
	err = hs.fillWithSecureJSONData(c.Req.Context(), &cmd)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return response.Error(500, "Failed to update datasource", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -410,7 +422,11 @@ func GetDataSourceIdByName(c *models.ReqContext) response.Response {
 | 
			
		||||
 | 
			
		||||
// /api/datasources/:id/resources/*
 | 
			
		||||
func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
 | 
			
		||||
	datasourceID := c.ParamsInt64(":id")
 | 
			
		||||
	datasourceID, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.JsonApiErr(http.StatusBadRequest, "id is invalid", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	ds, err := hs.DataSourceCache.GetDatasource(c.Req.Context(), datasourceID, c.SignedInUser, c.SkipCache)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if errors.Is(err, models.ErrDataSourceAccessDenied) {
 | 
			
		||||
@@ -465,7 +481,10 @@ func convertModelToDtos(ds *models.DataSource) dtos.DataSource {
 | 
			
		||||
// CheckDatasourceHealth sends a health check request to the plugin datasource
 | 
			
		||||
// /api/datasource/:id/health
 | 
			
		||||
func (hs *HTTPServer) CheckDatasourceHealth(c *models.ReqContext) response.Response {
 | 
			
		||||
	datasourceID := c.ParamsInt64(":id")
 | 
			
		||||
	datasourceID, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return response.Error(http.StatusBadRequest, "id is invalid", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ds, err := hs.DataSourceCache.GetDatasource(c.Req.Context(), datasourceID, c.SignedInUser, c.SkipCache)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user