Chore: Avoid aliasing importing models in api package (#22492)
This commit is contained in:
+31
-31
@@ -5,14 +5,14 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func GetDataSources(c *m.ReqContext) Response {
|
||||
query := m.GetDataSourcesQuery{OrgId: c.OrgId}
|
||||
func GetDataSources(c *models.ReqContext) Response {
|
||||
query := models.GetDataSourcesQuery{OrgId: c.OrgId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return Error(500, "Failed to query datasources", err)
|
||||
@@ -50,14 +50,14 @@ func GetDataSources(c *m.ReqContext) Response {
|
||||
return JSON(200, &result)
|
||||
}
|
||||
|
||||
func GetDataSourceById(c *m.ReqContext) Response {
|
||||
query := m.GetDataSourceByIdQuery{
|
||||
func GetDataSourceById(c *models.ReqContext) Response {
|
||||
query := models.GetDataSourceByIdQuery{
|
||||
Id: c.ParamsInt64(":id"),
|
||||
OrgId: c.OrgId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrDataSourceNotFound {
|
||||
if err == models.ErrDataSourceNotFound {
|
||||
return Error(404, "Data source not found", nil)
|
||||
}
|
||||
return Error(500, "Failed to query datasources", err)
|
||||
@@ -69,7 +69,7 @@ func GetDataSourceById(c *m.ReqContext) Response {
|
||||
return JSON(200, &dtos)
|
||||
}
|
||||
|
||||
func DeleteDataSourceById(c *m.ReqContext) Response {
|
||||
func DeleteDataSourceById(c *models.ReqContext) Response {
|
||||
id := c.ParamsInt64(":id")
|
||||
|
||||
if id <= 0 {
|
||||
@@ -85,7 +85,7 @@ func DeleteDataSourceById(c *m.ReqContext) Response {
|
||||
return Error(403, "Cannot delete read-only data source", nil)
|
||||
}
|
||||
|
||||
cmd := &m.DeleteDataSourceByIdCommand{Id: id, OrgId: c.OrgId}
|
||||
cmd := &models.DeleteDataSourceByIdCommand{Id: id, OrgId: c.OrgId}
|
||||
|
||||
err = bus.Dispatch(cmd)
|
||||
if err != nil {
|
||||
@@ -95,16 +95,16 @@ func DeleteDataSourceById(c *m.ReqContext) Response {
|
||||
return Success("Data source deleted")
|
||||
}
|
||||
|
||||
func DeleteDataSourceByName(c *m.ReqContext) Response {
|
||||
func DeleteDataSourceByName(c *models.ReqContext) Response {
|
||||
name := c.Params(":name")
|
||||
|
||||
if name == "" {
|
||||
return Error(400, "Missing valid datasource name", nil)
|
||||
}
|
||||
|
||||
getCmd := &m.GetDataSourceByNameQuery{Name: name, OrgId: c.OrgId}
|
||||
getCmd := &models.GetDataSourceByNameQuery{Name: name, OrgId: c.OrgId}
|
||||
if err := bus.Dispatch(getCmd); err != nil {
|
||||
if err == m.ErrDataSourceNotFound {
|
||||
if err == models.ErrDataSourceNotFound {
|
||||
return Error(404, "Data source not found", nil)
|
||||
}
|
||||
return Error(500, "Failed to delete datasource", err)
|
||||
@@ -114,7 +114,7 @@ func DeleteDataSourceByName(c *m.ReqContext) Response {
|
||||
return Error(403, "Cannot delete read-only data source", nil)
|
||||
}
|
||||
|
||||
cmd := &m.DeleteDataSourceByNameCommand{Name: name, OrgId: c.OrgId}
|
||||
cmd := &models.DeleteDataSourceByNameCommand{Name: name, OrgId: c.OrgId}
|
||||
err := bus.Dispatch(cmd)
|
||||
if err != nil {
|
||||
return Error(500, "Failed to delete datasource", err)
|
||||
@@ -123,11 +123,11 @@ func DeleteDataSourceByName(c *m.ReqContext) Response {
|
||||
return Success("Data source deleted")
|
||||
}
|
||||
|
||||
func AddDataSource(c *m.ReqContext, cmd m.AddDataSourceCommand) Response {
|
||||
func AddDataSource(c *models.ReqContext, cmd models.AddDataSourceCommand) Response {
|
||||
cmd.OrgId = c.OrgId
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == m.ErrDataSourceNameExists {
|
||||
if err == models.ErrDataSourceNameExists {
|
||||
return Error(409, err.Error(), err)
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func AddDataSource(c *m.ReqContext, cmd m.AddDataSourceCommand) Response {
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
|
||||
func UpdateDataSource(c *models.ReqContext, cmd models.UpdateDataSourceCommand) Response {
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.Id = c.ParamsInt64(":id")
|
||||
|
||||
@@ -154,19 +154,19 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
|
||||
|
||||
err = bus.Dispatch(&cmd)
|
||||
if err != nil {
|
||||
if err == m.ErrDataSourceUpdatingOldVersion {
|
||||
if err == models.ErrDataSourceUpdatingOldVersion {
|
||||
return Error(500, "Failed to update datasource. Reload new version and try again", err)
|
||||
}
|
||||
return Error(500, "Failed to update datasource", err)
|
||||
}
|
||||
|
||||
query := m.GetDataSourceByIdQuery{
|
||||
query := models.GetDataSourceByIdQuery{
|
||||
Id: cmd.Id,
|
||||
OrgId: c.OrgId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrDataSourceNotFound {
|
||||
if err == models.ErrDataSourceNotFound {
|
||||
return Error(404, "Data source not found", nil)
|
||||
}
|
||||
return Error(500, "Failed to query datasources", err)
|
||||
@@ -182,7 +182,7 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
|
||||
})
|
||||
}
|
||||
|
||||
func fillWithSecureJSONData(cmd *m.UpdateDataSourceCommand) error {
|
||||
func fillWithSecureJSONData(cmd *models.UpdateDataSourceCommand) error {
|
||||
if len(cmd.SecureJsonData) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func fillWithSecureJSONData(cmd *m.UpdateDataSourceCommand) error {
|
||||
}
|
||||
|
||||
if ds.ReadOnly {
|
||||
return m.ErrDatasourceIsReadOnly
|
||||
return models.ErrDatasourceIsReadOnly
|
||||
}
|
||||
|
||||
secureJSONData := ds.SecureJsonData.Decrypt()
|
||||
@@ -207,8 +207,8 @@ func fillWithSecureJSONData(cmd *m.UpdateDataSourceCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRawDataSourceById(id int64, orgID int64) (*m.DataSource, error) {
|
||||
query := m.GetDataSourceByIdQuery{
|
||||
func getRawDataSourceById(id int64, orgID int64) (*models.DataSource, error) {
|
||||
query := models.GetDataSourceByIdQuery{
|
||||
Id: id,
|
||||
OrgId: orgID,
|
||||
}
|
||||
@@ -221,11 +221,11 @@ func getRawDataSourceById(id int64, orgID int64) (*m.DataSource, error) {
|
||||
}
|
||||
|
||||
// Get /api/datasources/name/:name
|
||||
func GetDataSourceByName(c *m.ReqContext) Response {
|
||||
query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
|
||||
func GetDataSourceByName(c *models.ReqContext) Response {
|
||||
query := models.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrDataSourceNotFound {
|
||||
if err == models.ErrDataSourceNotFound {
|
||||
return Error(404, "Data source not found", nil)
|
||||
}
|
||||
return Error(500, "Failed to query datasources", err)
|
||||
@@ -236,11 +236,11 @@ func GetDataSourceByName(c *m.ReqContext) Response {
|
||||
}
|
||||
|
||||
// Get /api/datasources/id/:name
|
||||
func GetDataSourceIdByName(c *m.ReqContext) Response {
|
||||
query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
|
||||
func GetDataSourceIdByName(c *models.ReqContext) Response {
|
||||
query := models.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrDataSourceNotFound {
|
||||
if err == models.ErrDataSourceNotFound {
|
||||
return Error(404, "Data source not found", nil)
|
||||
}
|
||||
return Error(500, "Failed to query datasources", err)
|
||||
@@ -255,11 +255,11 @@ func GetDataSourceIdByName(c *m.ReqContext) Response {
|
||||
}
|
||||
|
||||
// /api/datasources/:id/resources/*
|
||||
func (hs *HTTPServer) CallDatasourceResource(c *m.ReqContext) {
|
||||
func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
|
||||
datasourceID := c.ParamsInt64(":id")
|
||||
ds, err := hs.DatasourceCache.GetDatasource(datasourceID, c.SignedInUser, c.SkipCache)
|
||||
if err != nil {
|
||||
if err == m.ErrDataSourceAccessDenied {
|
||||
if err == models.ErrDataSourceAccessDenied {
|
||||
c.JsonApiErr(403, "Access denied to datasource", err)
|
||||
return
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func (hs *HTTPServer) CallDatasourceResource(c *m.ReqContext) {
|
||||
hs.BackendPluginManager.CallResource(config, c, c.Params("*"))
|
||||
}
|
||||
|
||||
func convertModelToDtos(ds *m.DataSource) dtos.DataSource {
|
||||
func convertModelToDtos(ds *models.DataSource) dtos.DataSource {
|
||||
dto := dtos.DataSource{
|
||||
Id: ds.Id,
|
||||
OrgId: ds.OrgId,
|
||||
|
||||
Reference in New Issue
Block a user