Chore: Rename Id to ID in alerting models (#62777)
* Chore: Rename Id to ID in alerting models * Add xorm tags for datasource * Add xorm tag for uid
This commit is contained in:
+12
-12
@@ -30,7 +30,7 @@ func (hs *HTTPServer) ValidateOrgAlert(c *contextmodel.ReqContext) {
|
||||
c.JsonApiErr(http.StatusBadRequest, "alertId is invalid", nil)
|
||||
return
|
||||
}
|
||||
query := alertmodels.GetAlertByIdQuery{Id: id}
|
||||
query := alertmodels.GetAlertByIdQuery{ID: id}
|
||||
|
||||
res, err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
@@ -38,7 +38,7 @@ func (hs *HTTPServer) ValidateOrgAlert(c *contextmodel.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.OrgID != res.OrgId {
|
||||
if c.OrgID != res.OrgID {
|
||||
c.JsonApiErr(403, "You are not allowed to edit/view alert", nil)
|
||||
return
|
||||
}
|
||||
@@ -61,8 +61,8 @@ func (hs *HTTPServer) GetAlertStatesForDashboard(c *contextmodel.ReqContext) res
|
||||
}
|
||||
|
||||
query := alertmodels.GetAlertStatesForDashboardQuery{
|
||||
OrgId: c.OrgID,
|
||||
DashboardId: c.QueryInt64("dashboardId"),
|
||||
OrgID: c.OrgID,
|
||||
DashboardID: c.QueryInt64("dashboardId"),
|
||||
}
|
||||
|
||||
res, err := hs.AlertEngine.AlertStore.GetAlertStatesForDashboard(c.Req.Context(), &query)
|
||||
@@ -134,9 +134,9 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
query := alertmodels.GetAlertsQuery{
|
||||
OrgId: c.OrgID,
|
||||
OrgID: c.OrgID,
|
||||
DashboardIDs: dashboardIDs,
|
||||
PanelId: c.QueryInt64("panelId"),
|
||||
PanelID: c.QueryInt64("panelId"),
|
||||
Limit: c.QueryInt64("limit"),
|
||||
User: c.SignedInUser,
|
||||
Query: c.Query("query"),
|
||||
@@ -153,7 +153,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
for _, alert := range res {
|
||||
alert.Url = dashboards.GetDashboardURL(alert.DashboardUid, alert.DashboardSlug)
|
||||
alert.URL = dashboards.GetDashboardURL(alert.DashboardUID, alert.DashboardSlug)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, res)
|
||||
@@ -228,7 +228,7 @@ func (hs *HTTPServer) GetAlert(c *contextmodel.ReqContext) response.Response {
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "alertId is invalid", err)
|
||||
}
|
||||
query := alertmodels.GetAlertByIdQuery{Id: id}
|
||||
query := alertmodels.GetAlertByIdQuery{ID: id}
|
||||
|
||||
res, err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
@@ -698,13 +698,13 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *contextmod
|
||||
result := make(map[string]interface{})
|
||||
result["alertId"] = alertID
|
||||
|
||||
query := alertmodels.GetAlertByIdQuery{Id: alertID}
|
||||
query := alertmodels.GetAlertByIdQuery{ID: alertID}
|
||||
res, err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return response.Error(500, "Get Alert failed", err)
|
||||
}
|
||||
|
||||
guardian, err := guardian.New(c.Req.Context(), res.DashboardId, c.OrgID, c.SignedInUser)
|
||||
guardian, err := guardian.New(c.Req.Context(), res.DashboardID, c.OrgID, c.SignedInUser)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Error while creating permission guardian", err)
|
||||
}
|
||||
@@ -728,8 +728,8 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *contextmod
|
||||
}
|
||||
|
||||
cmd := alertmodels.PauseAlertCommand{
|
||||
OrgId: c.OrgID,
|
||||
AlertIds: []int64{alertID},
|
||||
OrgID: c.OrgID,
|
||||
AlertIDs: []int64{alertID},
|
||||
Paused: dto.Paused,
|
||||
}
|
||||
|
||||
|
||||
+42
-42
@@ -43,7 +43,7 @@ var secretsPluginError datasources.ErrDatasourceSecretsPluginUserFriendly
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetDataSources(c *contextmodel.ReqContext) response.Response {
|
||||
query := datasources.GetDataSourcesQuery{OrgId: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit}
|
||||
query := datasources.GetDataSourcesQuery{OrgID: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSources(c.Req.Context(), &query); err != nil {
|
||||
return response.Error(500, "Failed to query datasources", err)
|
||||
@@ -57,11 +57,11 @@ func (hs *HTTPServer) GetDataSources(c *contextmodel.ReqContext) response.Respon
|
||||
result := make(dtos.DataSourceList, 0)
|
||||
for _, ds := range filtered {
|
||||
dsItem := dtos.DataSourceListItemDTO{
|
||||
OrgId: ds.OrgId,
|
||||
Id: ds.Id,
|
||||
UID: ds.Uid,
|
||||
OrgId: ds.OrgID,
|
||||
Id: ds.ID,
|
||||
UID: ds.UID,
|
||||
Name: ds.Name,
|
||||
Url: ds.Url,
|
||||
Url: ds.URL,
|
||||
Type: ds.Type,
|
||||
TypeName: ds.Type,
|
||||
Access: ds.Access,
|
||||
@@ -112,8 +112,8 @@ func (hs *HTTPServer) GetDataSourceById(c *contextmodel.ReqContext) response.Res
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", nil)
|
||||
}
|
||||
query := datasources.GetDataSourceQuery{
|
||||
Id: id,
|
||||
OrgId: c.OrgID,
|
||||
ID: id,
|
||||
OrgID: c.OrgID,
|
||||
}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(c.Req.Context(), &query); err != nil {
|
||||
@@ -183,7 +183,7 @@ func (hs *HTTPServer) DeleteDataSourceById(c *contextmodel.ReqContext) response.
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, ds.Uid)
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, ds.UID)
|
||||
|
||||
return response.Success("Data source deleted")
|
||||
}
|
||||
@@ -262,11 +262,11 @@ func (hs *HTTPServer) DeleteDataSourceByUID(c *contextmodel.ReqContext) response
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, ds.Uid)
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, ds.UID)
|
||||
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"message": "Data source deleted",
|
||||
"id": ds.Id,
|
||||
"id": ds.ID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ func (hs *HTTPServer) DeleteDataSourceByName(c *contextmodel.ReqContext) respons
|
||||
return response.Error(400, "Missing valid datasource name", nil)
|
||||
}
|
||||
|
||||
getCmd := &datasources.GetDataSourceQuery{Name: name, OrgId: c.OrgID}
|
||||
getCmd := &datasources.GetDataSourceQuery{Name: name, OrgID: c.OrgID}
|
||||
if err := hs.DataSourcesService.GetDataSource(c.Req.Context(), getCmd); err != nil {
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) {
|
||||
return response.Error(404, "Data source not found", nil)
|
||||
@@ -311,11 +311,11 @@ func (hs *HTTPServer) DeleteDataSourceByName(c *contextmodel.ReqContext) respons
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, getCmd.Result.Uid)
|
||||
hs.Live.HandleDatasourceDelete(c.OrgID, getCmd.Result.UID)
|
||||
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"message": "Data source deleted",
|
||||
"id": getCmd.Result.Id,
|
||||
"id": getCmd.Result.ID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -371,11 +371,11 @@ func (hs *HTTPServer) AddDataSource(c *contextmodel.ReqContext) response.Respons
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
datasourcesLogger.Debug("Received command to add data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgID
|
||||
cmd.UserId = c.UserID
|
||||
if cmd.Url != "" {
|
||||
if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
|
||||
datasourcesLogger.Debug("Received command to add data source", "url", cmd.URL)
|
||||
cmd.OrgID = c.OrgID
|
||||
cmd.UserID = c.UserID
|
||||
if cmd.URL != "" {
|
||||
if resp := validateURL(cmd.Type, cmd.URL); resp != nil {
|
||||
return resp
|
||||
}
|
||||
}
|
||||
@@ -404,7 +404,7 @@ func (hs *HTTPServer) AddDataSource(c *contextmodel.ReqContext) response.Respons
|
||||
ds := hs.convertModelToDtos(c.Req.Context(), cmd.Result)
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"message": "Datasource added",
|
||||
"id": cmd.Result.Id,
|
||||
"id": cmd.Result.ID,
|
||||
"name": cmd.Result.Name,
|
||||
"datasource": ds,
|
||||
})
|
||||
@@ -436,20 +436,20 @@ func (hs *HTTPServer) UpdateDataSourceByID(c *contextmodel.ReqContext) response.
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgID
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.URL)
|
||||
cmd.OrgID = c.OrgID
|
||||
var err error
|
||||
if cmd.Id, err = strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64); err != nil {
|
||||
if cmd.ID, err = strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
|
||||
if resp := validateURL(cmd.Type, cmd.URL); resp != nil {
|
||||
return resp
|
||||
}
|
||||
if err := validateJSONData(cmd.JsonData, hs.Cfg); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Failed to update datasource", err)
|
||||
}
|
||||
|
||||
ds, err := hs.getRawDataSourceById(c.Req.Context(), cmd.Id, cmd.OrgId)
|
||||
ds, err := hs.getRawDataSourceById(c.Req.Context(), cmd.ID, cmd.OrgID)
|
||||
if err != nil {
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) {
|
||||
return response.Error(404, "Data source not found", nil)
|
||||
@@ -480,9 +480,9 @@ func (hs *HTTPServer) UpdateDataSourceByUID(c *contextmodel.ReqContext) response
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgID
|
||||
if resp := validateURL(cmd.Type, cmd.Url); resp != nil {
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.URL)
|
||||
cmd.OrgID = c.OrgID
|
||||
if resp := validateURL(cmd.Type, cmd.URL); resp != nil {
|
||||
return resp
|
||||
}
|
||||
if err := validateJSONData(cmd.JsonData, hs.Cfg); err != nil {
|
||||
@@ -496,7 +496,7 @@ func (hs *HTTPServer) UpdateDataSourceByUID(c *contextmodel.ReqContext) response
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update datasource", err)
|
||||
}
|
||||
cmd.Id = ds.Id
|
||||
cmd.ID = ds.ID
|
||||
return hs.updateDataSourceByID(c, ds, cmd)
|
||||
}
|
||||
|
||||
@@ -518,8 +518,8 @@ func (hs *HTTPServer) updateDataSourceByID(c *contextmodel.ReqContext, ds *datas
|
||||
}
|
||||
|
||||
query := datasources.GetDataSourceQuery{
|
||||
Id: cmd.Id,
|
||||
OrgId: c.OrgID,
|
||||
ID: cmd.ID,
|
||||
OrgID: c.OrgID,
|
||||
}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(c.Req.Context(), &query); err != nil {
|
||||
@@ -535,7 +535,7 @@ func (hs *HTTPServer) updateDataSourceByID(c *contextmodel.ReqContext, ds *datas
|
||||
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"message": "Datasource updated",
|
||||
"id": cmd.Id,
|
||||
"id": cmd.ID,
|
||||
"name": cmd.Name,
|
||||
"datasource": datasourceDTO,
|
||||
})
|
||||
@@ -543,8 +543,8 @@ func (hs *HTTPServer) updateDataSourceByID(c *contextmodel.ReqContext, ds *datas
|
||||
|
||||
func (hs *HTTPServer) getRawDataSourceById(ctx context.Context, id int64, orgID int64) (*datasources.DataSource, error) {
|
||||
query := datasources.GetDataSourceQuery{
|
||||
Id: id,
|
||||
OrgId: orgID,
|
||||
ID: id,
|
||||
OrgID: orgID,
|
||||
}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(ctx, &query); err != nil {
|
||||
@@ -556,8 +556,8 @@ func (hs *HTTPServer) getRawDataSourceById(ctx context.Context, id int64, orgID
|
||||
|
||||
func (hs *HTTPServer) getRawDataSourceByUID(ctx context.Context, uid string, orgID int64) (*datasources.DataSource, error) {
|
||||
query := datasources.GetDataSourceQuery{
|
||||
Uid: uid,
|
||||
OrgId: orgID,
|
||||
UID: uid,
|
||||
OrgID: orgID,
|
||||
}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(ctx, &query); err != nil {
|
||||
@@ -580,7 +580,7 @@ func (hs *HTTPServer) getRawDataSourceByUID(ctx context.Context, uid string, org
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetDataSourceByName(c *contextmodel.ReqContext) response.Response {
|
||||
query := datasources.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgID}
|
||||
query := datasources.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgID: c.OrgID}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(c.Req.Context(), &query); err != nil {
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) {
|
||||
@@ -607,7 +607,7 @@ func (hs *HTTPServer) GetDataSourceByName(c *contextmodel.ReqContext) response.R
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetDataSourceIdByName(c *contextmodel.ReqContext) response.Response {
|
||||
query := datasources.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgID}
|
||||
query := datasources.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgID: c.OrgID}
|
||||
|
||||
if err := hs.DataSourcesService.GetDataSource(c.Req.Context(), &query); err != nil {
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) {
|
||||
@@ -618,7 +618,7 @@ func (hs *HTTPServer) GetDataSourceIdByName(c *contextmodel.ReqContext) response
|
||||
|
||||
ds := query.Result
|
||||
dtos := dtos.AnyId{
|
||||
Id: ds.Id,
|
||||
Id: ds.ID,
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, &dtos)
|
||||
@@ -703,11 +703,11 @@ func (hs *HTTPServer) CallDatasourceResourceWithUID(c *contextmodel.ReqContext)
|
||||
|
||||
func (hs *HTTPServer) convertModelToDtos(ctx context.Context, ds *datasources.DataSource) dtos.DataSource {
|
||||
dto := dtos.DataSource{
|
||||
Id: ds.Id,
|
||||
UID: ds.Uid,
|
||||
OrgId: ds.OrgId,
|
||||
Id: ds.ID,
|
||||
UID: ds.UID,
|
||||
OrgId: ds.OrgID,
|
||||
Name: ds.Name,
|
||||
Url: ds.Url,
|
||||
Url: ds.URL,
|
||||
Type: ds.Type,
|
||||
Access: ds.Access,
|
||||
Database: ds.Database,
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestAddDataSource_InvalidURL(t *testing.T) {
|
||||
sc.m.Post(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: "Test",
|
||||
Url: "invalid:url",
|
||||
URL: "invalid:url",
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
})
|
||||
@@ -122,7 +122,7 @@ func TestAddDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
sc.m.Post(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: name,
|
||||
Url: url,
|
||||
URL: url,
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
})
|
||||
@@ -152,7 +152,7 @@ func TestAddDataSource_InvalidJSONData(t *testing.T) {
|
||||
sc.m.Post(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: "Test",
|
||||
Url: "localhost:5432",
|
||||
URL: "localhost:5432",
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
JsonData: jsonData,
|
||||
@@ -176,7 +176,7 @@ func TestUpdateDataSource_InvalidURL(t *testing.T) {
|
||||
sc.m.Put(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: "Test",
|
||||
Url: "invalid:url",
|
||||
URL: "invalid:url",
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
})
|
||||
@@ -204,7 +204,7 @@ func TestUpdateDataSource_InvalidJSONData(t *testing.T) {
|
||||
sc.m.Put(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: "Test",
|
||||
Url: "localhost:5432",
|
||||
URL: "localhost:5432",
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
JsonData: jsonData,
|
||||
@@ -236,7 +236,7 @@ func TestUpdateDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
sc.m.Put(sc.url, routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(datasources.AddDataSourceCommand{
|
||||
Name: name,
|
||||
Url: url,
|
||||
URL: url,
|
||||
Access: "direct",
|
||||
Type: "test",
|
||||
})
|
||||
|
||||
@@ -262,7 +262,7 @@ func isSupportBundlesEnabled(hs *HTTPServer) bool {
|
||||
func (hs *HTTPServer) getFSDataSources(c *contextmodel.ReqContext, enabledPlugins EnabledPlugins) (map[string]plugins.DataSourceDTO, error) {
|
||||
orgDataSources := make([]*datasources.DataSource, 0)
|
||||
if c.OrgID != 0 {
|
||||
query := datasources.GetDataSourcesQuery{OrgId: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit}
|
||||
query := datasources.GetDataSourcesQuery{OrgID: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit}
|
||||
err := hs.DataSourcesService.GetDataSources(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -283,15 +283,15 @@ func (hs *HTTPServer) getFSDataSources(c *contextmodel.ReqContext, enabledPlugin
|
||||
dataSources := make(map[string]plugins.DataSourceDTO)
|
||||
|
||||
for _, ds := range orgDataSources {
|
||||
url := ds.Url
|
||||
url := ds.URL
|
||||
|
||||
if ds.Access == datasources.DS_ACCESS_PROXY {
|
||||
url = "/api/datasources/proxy/uid/" + ds.Uid
|
||||
url = "/api/datasources/proxy/uid/" + ds.UID
|
||||
}
|
||||
|
||||
dsDTO := plugins.DataSourceDTO{
|
||||
ID: ds.Id,
|
||||
UID: ds.Uid,
|
||||
ID: ds.ID,
|
||||
UID: ds.UID,
|
||||
Type: ds.Type,
|
||||
Name: ds.Name,
|
||||
URL: url,
|
||||
@@ -365,7 +365,7 @@ func (hs *HTTPServer) getFSDataSources(c *contextmodel.ReqContext, enabledPlugin
|
||||
|
||||
if ds.Type == datasources.DS_PROMETHEUS {
|
||||
// add unproxied server URL for link to Prometheus web UI
|
||||
ds.JsonData.Set("directUrl", ds.Url)
|
||||
ds.JsonData.Set("directUrl", ds.URL)
|
||||
}
|
||||
|
||||
dataSources[ds.Name] = dsDTO
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewDataSourceProxy(ds *datasources.DataSource, pluginRoutes []*plugins.Rout
|
||||
proxyPath string, cfg *setting.Cfg, clientProvider httpclient.Provider,
|
||||
oAuthTokenService oauthtoken.OAuthTokenService, dsService datasources.DataSourceService,
|
||||
tracer tracing.Tracer) (*DataSourceProxy, error) {
|
||||
targetURL, err := datasource.ValidateURL(ds.Type, ds.Url)
|
||||
targetURL, err := datasource.ValidateURL(ds.Type, ds.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func (proxy *DataSourceProxy) director(req *http.Request) {
|
||||
}
|
||||
|
||||
ApplyRoute(req.Context(), req, proxy.proxyPath, proxy.matchedRoute, DSInfo{
|
||||
ID: proxy.ds.Id,
|
||||
ID: proxy.ds.ID,
|
||||
Updated: proxy.ds.Updated,
|
||||
JSONData: jsonData,
|
||||
DecryptedSecureJSONData: decryptedValues,
|
||||
|
||||
@@ -121,7 +121,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
jd, err := ds.JsonData.Map()
|
||||
require.NoError(t, err)
|
||||
dsInfo := DSInfo{
|
||||
ID: ds.Id,
|
||||
ID: ds.ID,
|
||||
Updated: ds.Updated,
|
||||
JSONData: jd,
|
||||
DecryptedSecureJSONData: map[string]string{
|
||||
@@ -307,7 +307,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
jd, err := ds.JsonData.Map()
|
||||
require.NoError(t, err)
|
||||
dsInfo := DSInfo{
|
||||
ID: ds.Id,
|
||||
ID: ds.ID,
|
||||
Updated: ds.Updated,
|
||||
JSONData: jd,
|
||||
DecryptedSecureJSONData: map[string]string{
|
||||
@@ -372,7 +372,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
|
||||
t.Run("When proxying graphite", func(t *testing.T) {
|
||||
var routes []*plugins.Route
|
||||
ds := &datasources.DataSource{Url: "htttp://graphite:8080", Type: datasources.DS_GRAPHITE}
|
||||
ds := &datasources.DataSource{URL: "htttp://graphite:8080", Type: datasources.DS_GRAPHITE}
|
||||
ctx := &contextmodel.ReqContext{}
|
||||
|
||||
sqlStore := db.InitTestDB(t)
|
||||
@@ -397,7 +397,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
t.Run("When proxying InfluxDB", func(t *testing.T) {
|
||||
ds := &datasources.DataSource{
|
||||
Type: datasources.DS_INFLUXDB_08,
|
||||
Url: "http://influxdb:8083",
|
||||
URL: "http://influxdb:8083",
|
||||
Database: "site",
|
||||
User: "user",
|
||||
}
|
||||
@@ -426,7 +426,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
|
||||
ds := &datasources.DataSource{
|
||||
Type: datasources.DS_GRAPHITE,
|
||||
Url: "http://graphite:8086",
|
||||
URL: "http://graphite:8086",
|
||||
JsonData: json,
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
|
||||
ds := &datasources.DataSource{
|
||||
Type: datasources.DS_GRAPHITE,
|
||||
Url: "http://graphite:8086",
|
||||
URL: "http://graphite:8086",
|
||||
JsonData: json,
|
||||
}
|
||||
|
||||
@@ -487,7 +487,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
t.Run("When proxying a custom datasource", func(t *testing.T) {
|
||||
ds := &datasources.DataSource{
|
||||
Type: "custom-datasource",
|
||||
Url: "http://host/root/",
|
||||
URL: "http://host/root/",
|
||||
}
|
||||
ctx := &contextmodel.ReqContext{}
|
||||
var routes []*plugins.Route
|
||||
@@ -515,7 +515,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
t.Run("When proxying a datasource that has OAuth token pass-through enabled", func(t *testing.T) {
|
||||
ds := &datasources.DataSource{
|
||||
Type: "custom-datasource",
|
||||
Url: "http://host/root/",
|
||||
URL: "http://host/root/",
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"oauthPassThru": true,
|
||||
}),
|
||||
@@ -657,7 +657,7 @@ func TestDataSourceProxy_requestHandling(t *testing.T) {
|
||||
}))
|
||||
t.Cleanup(backend.Close)
|
||||
|
||||
ds := &datasources.DataSource{Url: backend.URL, Type: datasources.DS_GRAPHITE}
|
||||
ds := &datasources.DataSource{URL: backend.URL, Type: datasources.DS_GRAPHITE}
|
||||
|
||||
responseWriter := web.NewResponseWriter("GET", httptest.NewRecorder())
|
||||
|
||||
@@ -829,7 +829,7 @@ func TestNewDataSourceProxy_InvalidURL(t *testing.T) {
|
||||
}
|
||||
ds := datasources.DataSource{
|
||||
Type: "test",
|
||||
Url: "://host/root",
|
||||
URL: "://host/root",
|
||||
}
|
||||
cfg := &setting.Cfg{}
|
||||
tracer := tracing.InitializeTracerForTest()
|
||||
@@ -853,7 +853,7 @@ func TestNewDataSourceProxy_ProtocolLessURL(t *testing.T) {
|
||||
}
|
||||
ds := datasources.DataSource{
|
||||
Type: "test",
|
||||
Url: "127.0.01:5432",
|
||||
URL: "127.0.01:5432",
|
||||
}
|
||||
cfg := &setting.Cfg{}
|
||||
tracer := tracing.InitializeTracerForTest()
|
||||
@@ -901,7 +901,7 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) {
|
||||
cfg := &setting.Cfg{}
|
||||
ds := datasources.DataSource{
|
||||
Type: "mssql",
|
||||
Url: tc.url,
|
||||
URL: tc.url,
|
||||
}
|
||||
|
||||
var routes []*plugins.Route
|
||||
@@ -916,7 +916,7 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &url.URL{
|
||||
Scheme: "sqlserver",
|
||||
Host: ds.Url,
|
||||
Host: ds.URL,
|
||||
}, p.targetUrl)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
@@ -930,7 +930,7 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) {
|
||||
func getDatasourceProxiedRequest(t *testing.T, ctx *contextmodel.ReqContext, cfg *setting.Cfg) *http.Request {
|
||||
ds := &datasources.DataSource{
|
||||
Type: "custom",
|
||||
Url: "http://host/root/",
|
||||
URL: "http://host/root/",
|
||||
}
|
||||
tracer := tracing.InitializeTracerForTest()
|
||||
|
||||
@@ -999,12 +999,12 @@ func createAuthTest(t *testing.T, secretsStore secretskvs.SecretsKVStore, dsType
|
||||
|
||||
test := &testCase{
|
||||
datasource: &datasources.DataSource{
|
||||
Id: 1,
|
||||
OrgId: 1,
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
Name: fmt.Sprintf("%s,%s,%s,%s", dsType, url, authType, authCheck),
|
||||
Type: dsType,
|
||||
JsonData: simplejson.New(),
|
||||
Url: url,
|
||||
URL: url,
|
||||
},
|
||||
}
|
||||
var message string
|
||||
@@ -1017,7 +1017,7 @@ func createAuthTest(t *testing.T, secretsStore secretskvs.SecretsKVStore, dsType
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = secretsStore.Set(context.Background(), test.datasource.OrgId, test.datasource.Name, "datasource", string(secureJsonData))
|
||||
err = secretsStore.Set(context.Background(), test.datasource.OrgID, test.datasource.Name, "datasource", string(secureJsonData))
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
message = fmt.Sprintf("%v should add basic auth username and password", dsType)
|
||||
@@ -1028,7 +1028,7 @@ func createAuthTest(t *testing.T, secretsStore secretskvs.SecretsKVStore, dsType
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = secretsStore.Set(context.Background(), test.datasource.OrgId, test.datasource.Name, "datasource", string(secureJsonData))
|
||||
err = secretsStore.Set(context.Background(), test.datasource.OrgID, test.datasource.Name, "datasource", string(secureJsonData))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user