From 7ddae870e7f81980b921f06da1af63464aaeea27 Mon Sep 17 00:00:00 2001 From: ying-jeanne <74549700+ying-jeanne@users.noreply.github.com> Date: Fri, 15 Apr 2022 14:01:58 +0200 Subject: [PATCH] fix status code 200 (#47818) --- pkg/api/admin.go | 2 +- pkg/api/admin_users.go | 2 +- pkg/api/alerting.go | 38 ++++++++++++------------- pkg/api/annotations.go | 8 +++--- pkg/api/apikey.go | 4 +-- pkg/api/comments.go | 4 +-- pkg/api/dashboard.go | 24 ++++++++-------- pkg/api/dashboard_permission.go | 2 +- pkg/api/dashboard_snapshot.go | 12 ++++---- pkg/api/datasources.go | 18 ++++++------ pkg/api/folder.go | 12 ++++---- pkg/api/folder_permission.go | 4 +-- pkg/api/frontendsettings.go | 3 +- pkg/api/index.go | 3 +- pkg/api/ldap_debug.go | 2 +- pkg/api/login.go | 8 +++--- pkg/api/org.go | 8 +++--- pkg/api/org_invite.go | 8 +++--- pkg/api/org_users.go | 10 +++---- pkg/api/password.go | 2 +- pkg/api/playlist.go | 14 ++++----- pkg/api/plugins.go | 10 +++---- pkg/api/preferences.go | 2 +- pkg/api/quota.go | 4 +-- pkg/api/response/response.go | 2 +- pkg/api/search.go | 2 +- pkg/api/short_url.go | 2 +- pkg/api/signup.go | 6 ++-- pkg/api/swagger.go | 8 ++++-- pkg/api/team.go | 6 ++-- pkg/api/team_members.go | 4 +-- pkg/api/user.go | 12 ++++---- pkg/api/user_token.go | 6 ++-- pkg/middleware/middleware_test.go | 4 +-- pkg/middleware/rate_limit_test.go | 2 +- pkg/services/featuremgmt/manager.go | 3 +- pkg/services/libraryelements/api.go | 14 ++++----- pkg/services/live/live.go | 4 +-- pkg/services/searchusers/searchusers.go | 6 ++-- pkg/services/store/http.go | 10 ++++--- pkg/services/thumbs/dummy.go | 7 +++-- pkg/services/thumbs/service.go | 11 +++---- pkg/tsdb/loki/framing_test.go | 2 +- pkg/tsdb/loki/loki_bench_test.go | 3 +- 44 files changed, 166 insertions(+), 152 deletions(-) diff --git a/pkg/api/admin.go b/pkg/api/admin.go index 453db021900..2ebe625d398 100644 --- a/pkg/api/admin.go +++ b/pkg/api/admin.go @@ -25,7 +25,7 @@ func (hs *HTTPServer) AdminGetStats(c *models.ReqContext) response.Response { return response.Error(500, "Failed to get admin stats from database", err) } - return response.JSON(200, statsQuery.Result) + return response.JSON(http.StatusOK, statsQuery.Result) } func (hs *HTTPServer) getAuthorizedSettings(ctx context.Context, user *models.SignedInUser, bag setting.SettingsBag) (setting.SettingsBag, error) { diff --git a/pkg/api/admin_users.go b/pkg/api/admin_users.go index c9fa2407533..78393beb864 100644 --- a/pkg/api/admin_users.go +++ b/pkg/api/admin_users.go @@ -58,7 +58,7 @@ func (hs *HTTPServer) AdminCreateUser(c *models.ReqContext) response.Response { Id: user.Id, } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) AdminUpdateUserPassword(c *models.ReqContext) response.Response { diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 86a57e8e9a6..4fa1589a9c7 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -54,7 +54,7 @@ func (hs *HTTPServer) GetAlertStatesForDashboard(c *models.ReqContext) response. return response.Error(500, "Failed to fetch alert states", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // GET /api/alerts @@ -106,7 +106,7 @@ func (hs *HTTPServer) GetAlerts(c *models.ReqContext) response.Response { // if we didn't find any dashboards, return empty result if len(dashboardIDs) == 0 { - return response.JSON(200, []*models.AlertListItemDTO{}) + return response.JSON(http.StatusOK, []*models.AlertListItemDTO{}) } } @@ -132,7 +132,7 @@ func (hs *HTTPServer) GetAlerts(c *models.ReqContext) response.Response { alert.Url = models.GetDashboardUrl(alert.DashboardUid, alert.DashboardSlug) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // POST /api/alerts/test @@ -176,7 +176,7 @@ func (hs *HTTPServer) AlertTest(c *models.ReqContext) response.Response { dtoRes.TimeMs = fmt.Sprintf("%1.3fms", res.GetDurationMs()) - return response.JSON(200, dtoRes) + return response.JSON(http.StatusOK, dtoRes) } // GET /api/alerts/:id @@ -191,17 +191,17 @@ func (hs *HTTPServer) GetAlert(c *models.ReqContext) response.Response { return response.Error(500, "List alerts failed", err) } - return response.JSON(200, &query.Result) + return response.JSON(http.StatusOK, &query.Result) } func (hs *HTTPServer) GetAlertNotifiers(ngalertEnabled bool) func(*models.ReqContext) response.Response { return func(_ *models.ReqContext) response.Response { if ngalertEnabled { - return response.JSON(200, notifier.GetAvailableNotifiers()) + return response.JSON(http.StatusOK, notifier.GetAvailableNotifiers()) } // TODO(codesome): This wont be required in 8.0 since ngalert // will be enabled by default with no disabling. This is to be removed later. - return response.JSON(200, alerting.GetNotifiers()) + return response.JSON(http.StatusOK, alerting.GetNotifiers()) } } @@ -217,7 +217,7 @@ func (hs *HTTPServer) GetAlertNotificationLookup(c *models.ReqContext) response. result = append(result, dtos.NewAlertNotificationLookup(notification)) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) GetAlertNotifications(c *models.ReqContext) response.Response { @@ -232,7 +232,7 @@ func (hs *HTTPServer) GetAlertNotifications(c *models.ReqContext) response.Respo result = append(result, dtos.NewAlertNotification(notification)) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) { @@ -267,7 +267,7 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *models.ReqContext) response.Re return response.Error(404, "Alert notification not found", nil) } - return response.JSON(200, dtos.NewAlertNotification(query.Result)) + return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result)) } func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.Response { @@ -288,7 +288,7 @@ func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.R return response.Error(404, "Alert notification not found", nil) } - return response.JSON(200, dtos.NewAlertNotification(query.Result)) + return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result)) } func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Response { @@ -309,7 +309,7 @@ func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Res return response.Error(500, "Failed to create alert notification", err) } - return response.JSON(200, dtos.NewAlertNotification(cmd.Result)) + return response.JSON(http.StatusOK, dtos.NewAlertNotification(cmd.Result)) } func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Response { @@ -344,7 +344,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res return response.Error(500, "Failed to get alert notification", err) } - return response.JSON(200, dtos.NewAlertNotification(query.Result)) + return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result)) } func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) response.Response { @@ -376,7 +376,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons return response.Error(500, "Failed to get alert notification", err) } - return response.JSON(200, dtos.NewAlertNotification(query.Result)) + return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result)) } func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error { @@ -469,7 +469,7 @@ func (hs *HTTPServer) DeleteAlertNotificationByUID(c *models.ReqContext) respons return response.Error(500, "Failed to delete alert notification", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Notification deleted", "id": cmd.DeletedAlertNotificationId, }) @@ -536,11 +536,11 @@ func (hs *HTTPServer) PauseAlert(c *models.ReqContext) response.Response { if query.Result.State != models.AlertStatePaused && !dto.Paused { result["state"] = "un-paused" result["message"] = "Alert is already un-paused" - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } else if query.Result.State == models.AlertStatePaused && dto.Paused { result["state"] = models.AlertStatePaused result["message"] = "Alert is already paused" - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } cmd := models.PauseAlertCommand{ @@ -562,7 +562,7 @@ func (hs *HTTPServer) PauseAlert(c *models.ReqContext) response.Response { result["state"] = resp result["message"] = "Alert " + pausedState - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } // POST /api/admin/pause-all-alerts @@ -592,5 +592,5 @@ func (hs *HTTPServer) PauseAllAlerts(c *models.ReqContext) response.Response { "alertsAffected": updateCmd.ResultCount, } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } diff --git a/pkg/api/annotations.go b/pkg/api/annotations.go index 9fd7cc61195..195c931fe76 100644 --- a/pkg/api/annotations.go +++ b/pkg/api/annotations.go @@ -47,7 +47,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response { } } - return response.JSON(200, items) + return response.JSON(http.StatusOK, items) } type AnnotationError struct { @@ -111,7 +111,7 @@ func (hs *HTTPServer) PostAnnotation(c *models.ReqContext) response.Response { startID := item.Id - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Annotation added", "id": startID, }) @@ -174,7 +174,7 @@ func (hs *HTTPServer) PostGraphiteAnnotation(c *models.ReqContext) response.Resp return response.Error(500, "Failed to save Graphite annotation", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Graphite annotation added", "id": item.Id, }) @@ -433,7 +433,7 @@ func (hs *HTTPServer) GetAnnotationTags(c *models.ReqContext) response.Response return response.Error(500, "Failed to find annotation tags", err) } - return response.JSON(200, annotations.GetAnnotationTagsResponse{Result: result}) + return response.JSON(http.StatusOK, annotations.GetAnnotationTagsResponse{Result: result}) } // AnnotationTypeScopeResolver provides an AttributeScopeResolver able to diff --git a/pkg/api/apikey.go b/pkg/api/apikey.go index 15599f037f6..9d1aab24bf3 100644 --- a/pkg/api/apikey.go +++ b/pkg/api/apikey.go @@ -36,7 +36,7 @@ func (hs *HTTPServer) GetAPIKeys(c *models.ReqContext) response.Response { } } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } // DeleteAPIKey deletes an API key @@ -107,5 +107,5 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext) response.Response { Key: newKeyInfo.ClientSecret, } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } diff --git a/pkg/api/comments.go b/pkg/api/comments.go index d84d4a8cd8f..7f32d64ac08 100644 --- a/pkg/api/comments.go +++ b/pkg/api/comments.go @@ -23,7 +23,7 @@ func (hs *HTTPServer) commentsGet(c *models.ReqContext) response.Response { } return response.Error(http.StatusInternalServerError, "internal error", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "comments": items, }) } @@ -43,7 +43,7 @@ func (hs *HTTPServer) commentsCreate(c *models.ReqContext) response.Response { } return response.Error(http.StatusInternalServerError, "internal error", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "comment": comment, }) } diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 343841cabaf..791a30172ce 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -72,7 +72,7 @@ func (hs *HTTPServer) TrimDashboard(c *models.ReqContext) response.Response { } c.TimeRequest(metrics.MApiDashboardGet) - return response.JSON(200, dto) + return response.JSON(http.StatusOK, dto) } func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { @@ -196,7 +196,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { } c.TimeRequest(metrics.MApiDashboardGet) - return response.JSON(200, dto) + return response.JSON(http.StatusOK, dto) } func (hs *HTTPServer) getAnnotationPermissionsByScope(c *models.ReqContext, actions *dtos.AnnotationActions, scope string) { @@ -282,7 +282,7 @@ func (hs *HTTPServer) deleteDashboard(c *models.ReqContext) response.Response { hs.log.Error("Failed to broadcast delete info", "dashboard", dash.Uid, "error", err) } } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "title": dash.Title, "message": fmt.Sprintf("Dashboard %s deleted", dash.Title), "id": dash.Id, @@ -396,7 +396,7 @@ func (hs *HTTPServer) postDashboard(c *models.ReqContext, cmd models.SaveDashboa } c.TimeRequest(metrics.MApiDashboardSave) - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "status": "success", "slug": dashboard.Slug, "version": dashboard.Version, @@ -417,7 +417,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response { if prefsQuery.Result.HomeDashboardId == 0 && len(homePage) > 0 { homePageRedirect := dtos.DashboardRedirect{RedirectUri: homePage} - return response.JSON(200, &homePageRedirect) + return response.JSON(http.StatusOK, &homePageRedirect) } if prefsQuery.Result.HomeDashboardId != 0 { @@ -426,7 +426,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response { if err == nil { url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug) dashRedirect := dtos.DashboardRedirect{RedirectUri: url} - return response.JSON(200, &dashRedirect) + return response.JSON(http.StatusOK, &dashRedirect) } hs.log.Warn("Failed to get slug from database", "err", err) } @@ -462,7 +462,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response { hs.addGettingStartedPanelToHomeDashboard(c, dash.Dashboard) - return response.JSON(200, &dash) + return response.JSON(http.StatusOK, &dash) } func (hs *HTTPServer) addGettingStartedPanelToHomeDashboard(c *models.ReqContext, dash *simplejson.Json) { @@ -530,7 +530,7 @@ func (hs *HTTPServer) GetDashboardVersions(c *models.ReqContext) response.Respon } } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // GetDashboardVersion returns the dashboard version with the given ID. @@ -573,7 +573,7 @@ func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Respons CreatedBy: creator, } - return response.JSON(200, dashVersionMeta) + return response.JSON(http.StatusOK, dashVersionMeta) } // POST /api/dashboards/calculate-diff performs diffs on two dashboards @@ -648,10 +648,10 @@ func (hs *HTTPServer) CalculateDashboardDiff(c *models.ReqContext) response.Resp } if options.DiffType == dashdiffs.DiffDelta { - return response.Respond(200, result.Delta).SetHeader("Content-Type", "application/json") + return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "application/json") } - return response.Respond(200, result.Delta).SetHeader("Content-Type", "text/html") + return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "text/html") } // RestoreDashboardVersion restores a dashboard to the given version. @@ -703,5 +703,5 @@ func (hs *HTTPServer) GetDashboardTags(c *models.ReqContext) { return } - c.JSON(200, query.Result) + c.JSON(http.StatusOK, query.Result) } diff --git a/pkg/api/dashboard_permission.go b/pkg/api/dashboard_permission.go index 34ea0b797f8..0415fe0262e 100644 --- a/pkg/api/dashboard_permission.go +++ b/pkg/api/dashboard_permission.go @@ -56,7 +56,7 @@ func (hs *HTTPServer) GetDashboardPermissionList(c *models.ReqContext) response. filteredAcls = append(filteredAcls, perm) } - return response.JSON(200, filteredAcls) + return response.JSON(http.StatusOK, filteredAcls) } func (hs *HTTPServer) UpdateDashboardPermissions(c *models.ReqContext) response.Response { diff --git a/pkg/api/dashboard_snapshot.go b/pkg/api/dashboard_snapshot.go index 1d5c45cc5f7..93fa34cd385 100644 --- a/pkg/api/dashboard_snapshot.go +++ b/pkg/api/dashboard_snapshot.go @@ -24,7 +24,7 @@ var client = &http.Client{ } func GetSharingOptions(c *models.ReqContext) { - c.JSON(200, util.DynMap{ + c.JSON(http.StatusOK, util.DynMap{ "externalSnapshotURL": setting.ExternalSnapshotUrl, "externalSnapshotName": setting.ExternalSnapshotName, "externalEnabled": setting.ExternalEnabled, @@ -138,7 +138,7 @@ func (hs *HTTPServer) CreateDashboardSnapshot(c *models.ReqContext) response.Res return nil } - c.JSON(200, util.DynMap{ + c.JSON(http.StatusOK, util.DynMap{ "key": cmd.Key, "deleteKey": cmd.DeleteKey, "url": url, @@ -181,7 +181,7 @@ func (hs *HTTPServer) GetDashboardSnapshot(c *models.ReqContext) response.Respon metrics.MApiDashboardSnapshotGet.Inc() - return response.JSON(200, dto).SetHeader("Cache-Control", "public, max-age=3600") + return response.JSON(http.StatusOK, dto).SetHeader("Cache-Control", "public, max-age=3600") } func deleteExternalDashboardSnapshot(externalUrl string) error { @@ -242,7 +242,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) r return response.Error(500, "Failed to delete dashboard snapshot", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches.", "id": query.Result.Id, }) @@ -290,7 +290,7 @@ func (hs *HTTPServer) DeleteDashboardSnapshot(c *models.ReqContext) response.Res return response.Error(500, "Failed to delete dashboard snapshot", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches.", "id": query.Result.Id, }) @@ -333,5 +333,5 @@ func (hs *HTTPServer) SearchDashboardSnapshots(c *models.ReqContext) response.Re } } - return response.JSON(200, dtos) + return response.JSON(http.StatusOK, dtos) } diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 71e18314d72..61a25517107 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -68,7 +68,7 @@ func (hs *HTTPServer) GetDataSources(c *models.ReqContext) response.Response { sort.Sort(result) - return response.JSON(200, &result) + return response.JSON(http.StatusOK, &result) } // GET /api/datasources/:id @@ -102,7 +102,7 @@ func (hs *HTTPServer) GetDataSourceById(c *models.ReqContext) response.Response // Add accesscontrol metadata dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID) - return response.JSON(200, &dto) + return response.JSON(http.StatusOK, &dto) } // DELETE /api/datasources/:id @@ -161,7 +161,7 @@ func (hs *HTTPServer) GetDataSourceByUID(c *models.ReqContext) response.Response // Add accesscontrol metadata dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID) - return response.JSON(200, &dto) + return response.JSON(http.StatusOK, &dto) } // DELETE /api/datasources/uid/:uid @@ -193,7 +193,7 @@ func (hs *HTTPServer) DeleteDataSourceByUID(c *models.ReqContext) response.Respo hs.Live.HandleDatasourceDelete(c.OrgId, ds.Uid) - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Data source deleted", "id": ds.Id, }) @@ -227,7 +227,7 @@ func (hs *HTTPServer) DeleteDataSourceByName(c *models.ReqContext) response.Resp hs.Live.HandleDatasourceDelete(c.OrgId, getCmd.Result.Uid) - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Data source deleted", "id": getCmd.Result.Id, }) @@ -266,7 +266,7 @@ func (hs *HTTPServer) AddDataSource(c *models.ReqContext) response.Response { } ds := convertModelToDtos(cmd.Result) - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Datasource added", "id": cmd.Result.Id, "name": cmd.Result.Name, @@ -331,7 +331,7 @@ func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext) response.Response { hs.Live.HandleDatasourceUpdate(c.OrgId, datasourceDTO.UID) - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Datasource updated", "id": cmd.Id, "name": cmd.Name, @@ -409,7 +409,7 @@ func (hs *HTTPServer) GetDataSourceByName(c *models.ReqContext) response.Respons } dto := convertModelToDtos(filtered[0]) - return response.JSON(200, &dto) + return response.JSON(http.StatusOK, &dto) } // Get /api/datasources/id/:name @@ -428,7 +428,7 @@ func (hs *HTTPServer) GetDataSourceIdByName(c *models.ReqContext) response.Respo Id: ds.Id, } - return response.JSON(200, &dtos) + return response.JSON(http.StatusOK, &dtos) } // /api/datasources/:id/resources/* diff --git a/pkg/api/folder.go b/pkg/api/folder.go index faee784f8a8..3a14be06d33 100644 --- a/pkg/api/folder.go +++ b/pkg/api/folder.go @@ -34,7 +34,7 @@ func (hs *HTTPServer) GetFolders(c *models.ReqContext) response.Response { }) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) GetFolderByUID(c *models.ReqContext) response.Response { @@ -44,7 +44,7 @@ func (hs *HTTPServer) GetFolderByUID(c *models.ReqContext) response.Response { } g := guardian.New(c.Req.Context(), folder.Id, c.OrgId, c.SignedInUser) - return response.JSON(200, hs.toFolderDto(c.Req.Context(), g, folder)) + return response.JSON(http.StatusOK, hs.toFolderDto(c.Req.Context(), g, folder)) } func (hs *HTTPServer) GetFolderByID(c *models.ReqContext) response.Response { @@ -58,7 +58,7 @@ func (hs *HTTPServer) GetFolderByID(c *models.ReqContext) response.Response { } g := guardian.New(c.Req.Context(), folder.Id, c.OrgId, c.SignedInUser) - return response.JSON(200, hs.toFolderDto(c.Req.Context(), g, folder)) + return response.JSON(http.StatusOK, hs.toFolderDto(c.Req.Context(), g, folder)) } func (hs *HTTPServer) CreateFolder(c *models.ReqContext) response.Response { @@ -72,7 +72,7 @@ func (hs *HTTPServer) CreateFolder(c *models.ReqContext) response.Response { } g := guardian.New(c.Req.Context(), folder.Id, c.OrgId, c.SignedInUser) - return response.JSON(200, hs.toFolderDto(c.Req.Context(), g, folder)) + return response.JSON(http.StatusOK, hs.toFolderDto(c.Req.Context(), g, folder)) } func (hs *HTTPServer) UpdateFolder(c *models.ReqContext) response.Response { @@ -86,7 +86,7 @@ func (hs *HTTPServer) UpdateFolder(c *models.ReqContext) response.Response { } g := guardian.New(c.Req.Context(), cmd.Result.Id, c.OrgId, c.SignedInUser) - return response.JSON(200, hs.toFolderDto(c.Req.Context(), g, cmd.Result)) + return response.JSON(http.StatusOK, hs.toFolderDto(c.Req.Context(), g, cmd.Result)) } func (hs *HTTPServer) DeleteFolder(c *models.ReqContext) response.Response { // temporarily adding this function to HTTPServer, will be removed from HTTPServer when librarypanels featuretoggle is removed @@ -103,7 +103,7 @@ func (hs *HTTPServer) DeleteFolder(c *models.ReqContext) response.Response { // return apierrors.ToFolderErrorResponse(err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "title": f.Title, "message": fmt.Sprintf("Folder %s deleted", f.Title), "id": f.Id, diff --git a/pkg/api/folder_permission.go b/pkg/api/folder_permission.go index 548201c7ba2..830c71b7afd 100644 --- a/pkg/api/folder_permission.go +++ b/pkg/api/folder_permission.go @@ -55,7 +55,7 @@ func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) response.Res filteredAcls = append(filteredAcls, perm) } - return response.JSON(200, filteredAcls) + return response.JSON(http.StatusOK, filteredAcls) } func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext) response.Response { @@ -141,7 +141,7 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext) response.Res return response.Error(500, "Failed to create permission", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "Folder permissions updated", "id": folder.Id, "title": folder.Title, diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index cc23170a9ed..2c341d53979 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" "strconv" "github.com/grafana/grafana/pkg/models" @@ -21,7 +22,7 @@ func (hs *HTTPServer) GetFrontendSettings(c *models.ReqContext) { return } - c.JSON(200, settings) + c.JSON(http.StatusOK, settings) } // getFrontendSettingsMap returns a json object with all the settings needed for front end initialisation. diff --git a/pkg/api/index.go b/pkg/api/index.go index ab2c2270e7e..d7d8f5e133a 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -2,6 +2,7 @@ package api import ( "fmt" + "net/http" "path" "sort" "strings" @@ -750,7 +751,7 @@ func (hs *HTTPServer) Index(c *models.ReqContext) { c.Handle(hs.Cfg, 500, "Failed to get settings", err) return } - c.HTML(200, "index", data) + c.HTML(http.StatusOK, "index", data) } func (hs *HTTPServer) NotFoundHandler(c *models.ReqContext) { diff --git a/pkg/api/ldap_debug.go b/pkg/api/ldap_debug.go index a477bceedd6..97b1e5142fe 100644 --- a/pkg/api/ldap_debug.go +++ b/pkg/api/ldap_debug.go @@ -314,7 +314,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response { return response.Error(http.StatusBadRequest, "Unable to find the teams for this user", err) } - return response.JSON(200, u) + return response.JSON(http.StatusOK, u) } // splitName receives the full name of a user and splits it into two parts: A name and a surname. diff --git a/pkg/api/login.go b/pkg/api/login.go index 49a33fa5744..b158afcbef8 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -85,7 +85,7 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) { urlParams := c.Req.URL.Query() if _, disableAutoLogin := urlParams["disableAutoLogin"]; disableAutoLogin { hs.log.Debug("Auto login manually disabled") - c.HTML(200, getViewIndex(), viewData) + c.HTML(http.StatusOK, getViewIndex(), viewData) return } @@ -109,7 +109,7 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) { // to login again via OAuth and enter to a redirect loop cookies.DeleteCookie(c.Resp, loginErrorCookieName, hs.CookieOptionsFromCfg) viewData.Settings["loginError"] = loginError - c.HTML(200, getViewIndex(), viewData) + c.HTML(http.StatusOK, getViewIndex(), viewData) return } @@ -144,7 +144,7 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) { return } - c.HTML(200, getViewIndex(), viewData) + c.HTML(http.StatusOK, getViewIndex(), viewData) } func (hs *HTTPServer) tryOAuthAutoLogin(c *models.ReqContext) bool { @@ -167,7 +167,7 @@ func (hs *HTTPServer) tryOAuthAutoLogin(c *models.ReqContext) bool { func (hs *HTTPServer) LoginAPIPing(c *models.ReqContext) response.Response { if c.IsSignedIn || c.IsAnonymous { - return response.JSON(200, "Logged in") + return response.JSON(http.StatusOK, "Logged in") } return response.Error(401, "Unauthorized", nil) diff --git a/pkg/api/org.go b/pkg/api/org.go index 21abb8fe5f0..d6cd5b3799b 100644 --- a/pkg/api/org.go +++ b/pkg/api/org.go @@ -54,7 +54,7 @@ func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response { }, } - return response.JSON(200, &result) + return response.JSON(http.StatusOK, &result) } func (hs *HTTPServer) getOrgHelper(ctx context.Context, orgID int64) response.Response { @@ -81,7 +81,7 @@ func (hs *HTTPServer) getOrgHelper(ctx context.Context, orgID int64) response.Re }, } - return response.JSON(200, &result) + return response.JSON(http.StatusOK, &result) } // POST /api/orgs @@ -105,7 +105,7 @@ func (hs *HTTPServer) CreateOrg(c *models.ReqContext) response.Response { metrics.MApiOrgCreate.Inc() - return response.JSON(200, &util.DynMap{ + return response.JSON(http.StatusOK, &util.DynMap{ "orgId": cmd.Result.Id, "message": "Organization created", }) @@ -226,5 +226,5 @@ func (hs *HTTPServer) SearchOrgs(c *models.ReqContext) response.Response { return response.Error(500, "Failed to search orgs", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 957053455dd..312971cdedc 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -28,7 +28,7 @@ func (hs *HTTPServer) GetPendingOrgInvites(c *models.ReqContext) response.Respon invite.Url = setting.ToAbsUrl("invite/" + invite.Code) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } func (hs *HTTPServer) AddOrgInvite(c *models.ReqContext) response.Response { @@ -131,7 +131,7 @@ func (hs *HTTPServer) inviteExistingUserToOrg(c *models.ReqContext, user *models } } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": fmt.Sprintf("Existing Grafana user %s added to org %s", user.NameOrFallback(), c.OrgName), "userId": user.Id, }) @@ -162,7 +162,7 @@ func (hs *HTTPServer) GetInviteInfoByCode(c *models.ReqContext) response.Respons return response.Error(404, "Invite not found", nil) } - return response.JSON(200, dtos.InviteInfo{ + return response.JSON(http.StatusOK, dtos.InviteInfo{ Email: invite.Email, Name: invite.Name, Username: invite.Email, @@ -225,7 +225,7 @@ func (hs *HTTPServer) CompleteInvite(c *models.ReqContext) response.Response { metrics.MApiUserSignUpCompleted.Inc() metrics.MApiUserSignUpInvite.Inc() - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "User created and logged in", "id": user.Id, }) diff --git a/pkg/api/org_users.go b/pkg/api/org_users.go index dcd45bbe523..b10aae80c45 100644 --- a/pkg/api/org_users.go +++ b/pkg/api/org_users.go @@ -64,7 +64,7 @@ func (hs *HTTPServer) addOrgUserHelper(ctx context.Context, cmd models.AddOrgUse return response.Error(500, "Could not add user to organization", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "User added to organization", "userId": cmd.UserId, }) @@ -83,7 +83,7 @@ func (hs *HTTPServer) GetOrgUsersForCurrentOrg(c *models.ReqContext) response.Re return response.Error(500, "Failed to get users for current organization", err) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } // GET /api/org/users/lookup @@ -109,7 +109,7 @@ func (hs *HTTPServer) GetOrgUsersForCurrentOrgLookup(c *models.ReqContext) respo }) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } // GET /api/orgs/:orgId/users @@ -130,7 +130,7 @@ func (hs *HTTPServer) GetOrgUsers(c *models.ReqContext) response.Response { return response.Error(500, "Failed to get users for organization", err) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) getOrgUsersHelper(c *models.ReqContext, query *models.GetOrgUsersQuery, signedInUser *models.SignedInUser) ([]*models.OrgUserDTO, error) { @@ -201,7 +201,7 @@ func (hs *HTTPServer) SearchOrgUsersWithPaging(c *models.ReqContext) response.Re query.Result.Page = page query.Result.PerPage = perPage - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // PATCH /api/org/users/:userId diff --git a/pkg/api/password.go b/pkg/api/password.go index 487c1e1c33d..4454a486001 100644 --- a/pkg/api/password.go +++ b/pkg/api/password.go @@ -29,7 +29,7 @@ func (hs *HTTPServer) SendResetPasswordEmail(c *models.ReqContext) response.Resp if err := hs.SQLStore.GetUserByLogin(c.Req.Context(), &userQuery); err != nil { c.Logger.Info("Requested password reset for user that was not found", "user", userQuery.LoginOrEmail) - return response.Error(200, "Email sent", err) + return response.Error(http.StatusOK, "Email sent", err) } emailCmd := models.SendResetPasswordEmailCommand{User: userQuery.Result} diff --git a/pkg/api/playlist.go b/pkg/api/playlist.go index 5e496c0fd0e..d30f8c58b23 100644 --- a/pkg/api/playlist.go +++ b/pkg/api/playlist.go @@ -54,7 +54,7 @@ func (hs *HTTPServer) SearchPlaylists(c *models.ReqContext) response.Response { return response.Error(500, "Search failed", err) } - return response.JSON(200, searchQuery.Result) + return response.JSON(http.StatusOK, searchQuery.Result) } func (hs *HTTPServer) GetPlaylist(c *models.ReqContext) response.Response { @@ -78,7 +78,7 @@ func (hs *HTTPServer) GetPlaylist(c *models.ReqContext) response.Response { Items: playlistDTOs, } - return response.JSON(200, dto) + return response.JSON(http.StatusOK, dto) } func (hs *HTTPServer) LoadPlaylistItemDTOs(ctx context.Context, id int64) ([]models.PlaylistItemDTO, error) { @@ -125,7 +125,7 @@ func (hs *HTTPServer) GetPlaylistItems(c *models.ReqContext) response.Response { return response.Error(500, "Could not load playlist items", err) } - return response.JSON(200, playlistDTOs) + return response.JSON(http.StatusOK, playlistDTOs) } func (hs *HTTPServer) GetPlaylistDashboards(c *models.ReqContext) response.Response { @@ -139,7 +139,7 @@ func (hs *HTTPServer) GetPlaylistDashboards(c *models.ReqContext) response.Respo return response.Error(500, "Could not load dashboards", err) } - return response.JSON(200, playlists) + return response.JSON(http.StatusOK, playlists) } func (hs *HTTPServer) DeletePlaylist(c *models.ReqContext) response.Response { @@ -153,7 +153,7 @@ func (hs *HTTPServer) DeletePlaylist(c *models.ReqContext) response.Response { return response.Error(500, "Failed to delete playlist", err) } - return response.JSON(200, "") + return response.JSON(http.StatusOK, "") } func (hs *HTTPServer) CreatePlaylist(c *models.ReqContext) response.Response { @@ -167,7 +167,7 @@ func (hs *HTTPServer) CreatePlaylist(c *models.ReqContext) response.Response { return response.Error(500, "Failed to create playlist", err) } - return response.JSON(200, cmd.Result) + return response.JSON(http.StatusOK, cmd.Result) } func (hs *HTTPServer) UpdatePlaylist(c *models.ReqContext) response.Response { @@ -192,5 +192,5 @@ func (hs *HTTPServer) UpdatePlaylist(c *models.ReqContext) response.Response { } cmd.Result.Items = playlistDTOs - return response.JSON(200, cmd.Result) + return response.JSON(http.StatusOK, cmd.Result) } diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index 25a1dcbfe60..227a6d6fba1 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -111,7 +111,7 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) response.Response { } sort.Sort(result) - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) GetPluginSettingByID(c *models.ReqContext) response.Response { @@ -163,7 +163,7 @@ func (hs *HTTPServer) GetPluginSettingByID(c *models.ReqContext) response.Respon dto.HasUpdate = true } - return response.JSON(200, dto) + return response.JSON(http.StatusOK, dto) } func (hs *HTTPServer) UpdatePluginSetting(c *models.ReqContext) response.Response { @@ -217,7 +217,7 @@ func (hs *HTTPServer) GetPluginMarkdown(c *models.ReqContext) response.Response } } - resp := response.Respond(200, content) + resp := response.Respond(http.StatusOK, content) resp.SetHeader("Content-Type", "text/plain; charset=utf-8") return resp } @@ -343,7 +343,7 @@ func (hs *HTTPServer) CheckHealth(c *models.ReqContext) response.Response { return response.JSON(503, payload) } - return response.JSON(200, payload) + return response.JSON(http.StatusOK, payload) } // CallResource passes a resource call from a plugin to the backend plugin. @@ -354,7 +354,7 @@ func (hs *HTTPServer) CallResource(c *models.ReqContext) { } func (hs *HTTPServer) GetPluginErrorsList(_ *models.ReqContext) response.Response { - return response.JSON(200, hs.pluginErrorResolver.PluginErrors()) + return response.JSON(http.StatusOK, hs.pluginErrorResolver.PluginErrors()) } func (hs *HTTPServer) InstallPlugin(c *models.ReqContext) response.Response { diff --git a/pkg/api/preferences.go b/pkg/api/preferences.go index c15530d8475..3792bee5a90 100644 --- a/pkg/api/preferences.go +++ b/pkg/api/preferences.go @@ -56,7 +56,7 @@ func (hs *HTTPServer) getPreferencesFor(ctx context.Context, orgID, userID, team dto.QueryHistory = prefsQuery.Result.JsonData.QueryHistory } - return response.JSON(200, &dto) + return response.JSON(http.StatusOK, &dto) } // PUT /api/user/preferences diff --git a/pkg/api/quota.go b/pkg/api/quota.go index cdd8c9762d1..79d304dbf9e 100644 --- a/pkg/api/quota.go +++ b/pkg/api/quota.go @@ -32,7 +32,7 @@ func (hs *HTTPServer) getOrgQuotasHelper(c *models.ReqContext, orgID int64) resp return response.Error(500, "Failed to get org quotas", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } func (hs *HTTPServer) UpdateOrgQuota(c *models.ReqContext) response.Response { @@ -76,7 +76,7 @@ func (hs *HTTPServer) GetUserQuotas(c *models.ReqContext) response.Response { return response.Error(500, "Failed to get org quotas", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } func (hs *HTTPServer) UpdateUserQuota(c *models.ReqContext) response.Response { diff --git a/pkg/api/response/response.go b/pkg/api/response/response.go index 58de6282652..e08ed4eb974 100644 --- a/pkg/api/response/response.go +++ b/pkg/api/response/response.go @@ -180,7 +180,7 @@ func JSONStreaming(status int, body interface{}) StreamingResponse { func Success(message string) *NormalResponse { resp := make(map[string]interface{}) resp["message"] = message - return JSON(200, resp) + return JSON(http.StatusOK, resp) } // Error creates an error response. diff --git a/pkg/api/search.go b/pkg/api/search.go index 2f1a2cbf407..a981250d4d4 100644 --- a/pkg/api/search.go +++ b/pkg/api/search.go @@ -67,7 +67,7 @@ func (hs *HTTPServer) Search(c *models.ReqContext) response.Response { } c.TimeRequest(metrics.MApiDashboardSearch) - return response.JSON(200, searchQuery.Result) + return response.JSON(http.StatusOK, searchQuery.Result) } func (hs *HTTPServer) ListSortOptions(c *models.ReqContext) response.Response { diff --git a/pkg/api/short_url.go b/pkg/api/short_url.go index 180aeedfd73..6e9d1614d1f 100644 --- a/pkg/api/short_url.go +++ b/pkg/api/short_url.go @@ -47,7 +47,7 @@ func (hs *HTTPServer) createShortURL(c *models.ReqContext) response.Response { URL: url, } - return response.JSON(200, dto) + return response.JSON(http.StatusOK, dto) } func (hs *HTTPServer) redirectFromShortURL(c *models.ReqContext) { diff --git a/pkg/api/signup.go b/pkg/api/signup.go index f3568d03daf..69591220c93 100644 --- a/pkg/api/signup.go +++ b/pkg/api/signup.go @@ -18,7 +18,7 @@ import ( // GET /api/user/signup/options func GetSignUpOptions(c *models.ReqContext) response.Response { - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "verifyEmailEnabled": setting.VerifyEmailEnabled, "autoAssignOrg": setting.AutoAssignOrg, }) @@ -64,7 +64,7 @@ func (hs *HTTPServer) SignUp(c *models.ReqContext) response.Response { metrics.MApiUserSignUpStarted.Inc() - return response.JSON(200, util.DynMap{"status": "SignUpCreated"}) + return response.JSON(http.StatusOK, util.DynMap{"status": "SignUpCreated"}) } func (hs *HTTPServer) SignUpStep2(c *models.ReqContext) response.Response { @@ -135,7 +135,7 @@ func (hs *HTTPServer) SignUpStep2(c *models.ReqContext) response.Response { metrics.MApiUserSignUpCompleted.Inc() - return response.JSON(200, apiResponse) + return response.JSON(http.StatusOK, apiResponse) } func (hs *HTTPServer) verifyUserSignUpEmail(ctx context.Context, email string, code string) (bool, response.Response) { diff --git a/pkg/api/swagger.go b/pkg/api/swagger.go index 37d88541e72..7c96b576b9f 100644 --- a/pkg/api/swagger.go +++ b/pkg/api/swagger.go @@ -1,7 +1,11 @@ package api -import "github.com/grafana/grafana/pkg/models" +import ( + "net/http" + + "github.com/grafana/grafana/pkg/models" +) func swaggerUI(c *models.ReqContext) { - c.HTML(200, "swagger", nil) + c.HTML(http.StatusOK, "swagger", nil) } diff --git a/pkg/api/team.go b/pkg/api/team.go index 77416f5bce8..79c0eac9982 100644 --- a/pkg/api/team.go +++ b/pkg/api/team.go @@ -44,7 +44,7 @@ func (hs *HTTPServer) CreateTeam(c *models.ReqContext) response.Response { c.Logger.Warn("Could not add creator to team because is not a real user") } } - return response.JSON(200, &util.DynMap{ + return response.JSON(http.StatusOK, &util.DynMap{ "teamId": team.Id, "message": "Team created", }) @@ -151,7 +151,7 @@ func (hs *HTTPServer) SearchTeams(c *models.ReqContext) response.Response { query.Result.Page = page query.Result.PerPage = perPage - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // UserFilter returns the user ID used in a filter when querying a team @@ -198,7 +198,7 @@ func (hs *HTTPServer) GetTeamByID(c *models.ReqContext) response.Response { query.Result.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, "teams:id:", strconv.FormatInt(query.Result.Id, 10)) query.Result.AvatarUrl = dtos.GetGravatarUrlWithDefault(query.Result.Email, query.Result.Name) - return response.JSON(200, &query.Result) + return response.JSON(http.StatusOK, &query.Result) } // GET /api/teams/:teamId/preferences diff --git a/pkg/api/team_members.go b/pkg/api/team_members.go index e39028872e8..a8c44cde66a 100644 --- a/pkg/api/team_members.go +++ b/pkg/api/team_members.go @@ -54,7 +54,7 @@ func (hs *HTTPServer) GetTeamMembers(c *models.ReqContext) response.Response { filteredMembers = append(filteredMembers, member) } - return response.JSON(200, filteredMembers) + return response.JSON(http.StatusOK, filteredMembers) } // POST /api/teams/:teamId/members @@ -89,7 +89,7 @@ func (hs *HTTPServer) AddTeamMember(c *models.ReqContext) response.Response { return response.Error(500, "Failed to add Member to Team", err) } - return response.JSON(200, &util.DynMap{ + return response.JSON(http.StatusOK, &util.DynMap{ "message": "Member added to Team", }) } diff --git a/pkg/api/user.go b/pkg/api/user.go index 95b69d0b462..8b0c59debf7 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -49,7 +49,7 @@ func (hs *HTTPServer) getUserUserProfile(c *models.ReqContext, userID int64) res query.Result.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, "global.users:id:", strconv.FormatInt(userID, 10)) query.Result.AvatarUrl = dtos.GetGravatarUrl(query.Result.Email) - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // GET /api/users/lookup @@ -73,7 +73,7 @@ func (hs *HTTPServer) GetUserByLoginOrEmail(c *models.ReqContext) response.Respo UpdatedAt: user.Updated, CreatedAt: user.Created, } - return response.JSON(200, &result) + return response.JSON(http.StatusOK, &result) } // POST /api/user @@ -176,7 +176,7 @@ func (hs *HTTPServer) getUserTeamList(ctx context.Context, orgID int64, userID i for _, team := range query.Result { team.AvatarUrl = dtos.GetGravatarUrlWithDefault(team.Email, team.Name) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } // GET /api/users/:id/orgs @@ -195,7 +195,7 @@ func (hs *HTTPServer) getUserOrgList(ctx context.Context, userID int64) response return response.Error(500, "Failed to get user organizations", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } func (hs *HTTPServer) validateUsingOrg(ctx context.Context, userID int64, orgID int64) bool { @@ -321,7 +321,7 @@ func (hs *HTTPServer) SetHelpFlag(c *models.ReqContext) response.Response { return response.Error(500, "Failed to update help flag", err) } - return response.JSON(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1}) + return response.JSON(http.StatusOK, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1}) } func (hs *HTTPServer) ClearHelpFlags(c *models.ReqContext) response.Response { @@ -334,7 +334,7 @@ func (hs *HTTPServer) ClearHelpFlags(c *models.ReqContext) response.Response { return response.Error(500, "Failed to update help flag", err) } - return response.JSON(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1}) + return response.JSON(http.StatusOK, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1}) } func GetAuthProviderLabel(authModule string) string { diff --git a/pkg/api/user_token.go b/pkg/api/user_token.go index 53b040bd531..edb5c34da41 100644 --- a/pkg/api/user_token.go +++ b/pkg/api/user_token.go @@ -43,7 +43,7 @@ func (hs *HTTPServer) logoutUserFromAllDevicesInternal(ctx context.Context, user return response.Error(500, "Failed to logout user", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "User logged out", }) } @@ -112,7 +112,7 @@ func (hs *HTTPServer) getUserAuthTokensInternal(c *models.ReqContext, userID int }) } - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (hs *HTTPServer) revokeUserAuthTokenInternal(c *models.ReqContext, userID int64, cmd models.RevokeAuthTokenCmd) response.Response { @@ -144,7 +144,7 @@ func (hs *HTTPServer) revokeUserAuthTokenInternal(c *models.ReqContext, userID i return response.Error(500, "Failed to revoke user auth token", err) } - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "message": "User auth token revoked", }) } diff --git a/pkg/middleware/middleware_test.go b/pkg/middleware/middleware_test.go index 76dbd87b1be..a4fbd7c7629 100644 --- a/pkg/middleware/middleware_test.go +++ b/pkg/middleware/middleware_test.go @@ -111,7 +111,7 @@ func TestMiddlewareContext(t *testing.T) { NavTree: []*dtos.NavLink{}, } t.Log("Calling HTML", "data", data) - c.HTML(200, "index-template", data) + c.HTML(http.StatusOK, "index-template", data) t.Log("Returned HTML with code 200") } sc.fakeReq("GET", "/").exec() @@ -616,7 +616,7 @@ func middlewareScenario(t *testing.T, desc string, fn scenarioFunc, cbs ...func( t.Log("Returning JSON OK") resp := make(map[string]interface{}) resp["message"] = "OK" - c.JSON(200, resp) + c.JSON(http.StatusOK, resp) } } diff --git a/pkg/middleware/rate_limit_test.go b/pkg/middleware/rate_limit_test.go index 641e385018a..88fb7e021c5 100644 --- a/pkg/middleware/rate_limit_test.go +++ b/pkg/middleware/rate_limit_test.go @@ -25,7 +25,7 @@ func rateLimiterScenario(t *testing.T, desc string, rps int, burst int, fn rateL defaultHandler := func(c *models.ReqContext) { resp := make(map[string]interface{}) resp["message"] = "OK" - c.JSON(200, resp) + c.JSON(http.StatusOK, resp) } currentTime := time.Now() diff --git a/pkg/services/featuremgmt/manager.go b/pkg/services/featuremgmt/manager.go index 1b795d0348d..8593e6635cf 100644 --- a/pkg/services/featuremgmt/manager.go +++ b/pkg/services/featuremgmt/manager.go @@ -3,6 +3,7 @@ package featuremgmt import ( "context" "fmt" + "net/http" "reflect" "github.com/grafana/grafana/pkg/infra/log" @@ -157,7 +158,7 @@ func (fm *FeatureManager) HandleGetSettings(c *models.ReqContext) { res["info"] = vv - response.JSON(200, res).WriteTo(c) + response.JSON(http.StatusOK, res).WriteTo(c) } // WithFeatures is used to define feature toggles for testing. diff --git a/pkg/services/libraryelements/api.go b/pkg/services/libraryelements/api.go index 8babbe60046..f14c876b8e4 100644 --- a/pkg/services/libraryelements/api.go +++ b/pkg/services/libraryelements/api.go @@ -35,7 +35,7 @@ func (l *LibraryElementService) createHandler(c *models.ReqContext) response.Res return toLibraryElementError(err, "Failed to create library element") } - return response.JSON(200, LibraryElementResponse{Result: element}) + return response.JSON(http.StatusOK, LibraryElementResponse{Result: element}) } // deleteHandler handles DELETE /api/library-elements/:uid. @@ -45,7 +45,7 @@ func (l *LibraryElementService) deleteHandler(c *models.ReqContext) response.Res return toLibraryElementError(err, "Failed to delete library element") } - return response.JSON(200, DeleteLibraryElementResponse{ + return response.JSON(http.StatusOK, DeleteLibraryElementResponse{ Message: "Library element deleted", ID: id, }) @@ -58,7 +58,7 @@ func (l *LibraryElementService) getHandler(c *models.ReqContext) response.Respon return toLibraryElementError(err, "Failed to get library element") } - return response.JSON(200, LibraryElementResponse{Result: element}) + return response.JSON(http.StatusOK, LibraryElementResponse{Result: element}) } // getAllHandler handles GET /api/library-elements/. @@ -78,7 +78,7 @@ func (l *LibraryElementService) getAllHandler(c *models.ReqContext) response.Res return toLibraryElementError(err, "Failed to get library elements") } - return response.JSON(200, LibraryElementSearchResponse{Result: elementsResult}) + return response.JSON(http.StatusOK, LibraryElementSearchResponse{Result: elementsResult}) } // patchHandler handles PATCH /api/library-elements/:uid @@ -93,7 +93,7 @@ func (l *LibraryElementService) patchHandler(c *models.ReqContext) response.Resp return toLibraryElementError(err, "Failed to update library element") } - return response.JSON(200, LibraryElementResponse{Result: element}) + return response.JSON(http.StatusOK, LibraryElementResponse{Result: element}) } // getConnectionsHandler handles GET /api/library-panels/:uid/connections/. @@ -103,7 +103,7 @@ func (l *LibraryElementService) getConnectionsHandler(c *models.ReqContext) resp return toLibraryElementError(err, "Failed to get connections") } - return response.JSON(200, LibraryElementConnectionsResponse{Result: connections}) + return response.JSON(http.StatusOK, LibraryElementConnectionsResponse{Result: connections}) } // getByNameHandler handles GET /api/library-elements/name/:name/. @@ -113,7 +113,7 @@ func (l *LibraryElementService) getByNameHandler(c *models.ReqContext) response. return toLibraryElementError(err, "Failed to get library element") } - return response.JSON(200, LibraryElementArrayResponse{Result: elements}) + return response.JSON(http.StatusOK, LibraryElementArrayResponse{Result: elements}) } func toLibraryElementError(err error, message string) response.Response { diff --git a/pkg/services/live/live.go b/pkg/services/live/live.go index 3924d6f810e..1dba33d32b3 100644 --- a/pkg/services/live/live.go +++ b/pkg/services/live/live.go @@ -1042,14 +1042,14 @@ func (g *GrafanaLive) HandleListHTTP(c *models.ReqContext) response.Response { info := streamChannelListResponse{ Channels: channels, } - return response.JSONStreaming(200, info) + return response.JSONStreaming(http.StatusOK, info) } // HandleInfoHTTP special http response for func (g *GrafanaLive) HandleInfoHTTP(ctx *models.ReqContext) response.Response { path := web.Params(ctx.Req)["*"] if path == "grafana/dashboards/gitops" { - return response.JSON(200, util.DynMap{ + return response.JSON(http.StatusOK, util.DynMap{ "active": g.GrafanaScope.Dashboards.HasGitOpsObserver(ctx.SignedInUser.OrgId), }) } diff --git a/pkg/services/searchusers/searchusers.go b/pkg/services/searchusers/searchusers.go index 79dc1b59196..fbed2051dae 100644 --- a/pkg/services/searchusers/searchusers.go +++ b/pkg/services/searchusers/searchusers.go @@ -1,6 +1,8 @@ package searchusers import ( + "net/http" + "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/models" @@ -27,7 +29,7 @@ func (s *OSSService) SearchUsers(c *models.ReqContext) response.Response { return response.Error(500, "Failed to fetch users", err) } - return response.JSON(200, query.Result.Users) + return response.JSON(http.StatusOK, query.Result.Users) } func (s *OSSService) SearchUsersWithPaging(c *models.ReqContext) response.Response { @@ -36,7 +38,7 @@ func (s *OSSService) SearchUsersWithPaging(c *models.ReqContext) response.Respon return response.Error(500, "Failed to fetch users", err) } - return response.JSON(200, query.Result) + return response.JSON(http.StatusOK, query.Result) } func (s *OSSService) SearchUser(c *models.ReqContext) (*models.SearchUsersQuery, error) { diff --git a/pkg/services/store/http.go b/pkg/services/store/http.go index 5d23128a8cf..7334049d395 100644 --- a/pkg/services/store/http.go +++ b/pkg/services/store/http.go @@ -1,6 +1,8 @@ package store import ( + "net/http" + "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/web" @@ -28,7 +30,7 @@ func (s *httpStorage) Upload(c *models.ReqContext) response.Response { action := "Upload" scope, path := getPathAndScope(c) - return response.JSON(200, map[string]string{ + return response.JSON(http.StatusOK, map[string]string{ "action": action, "scope": scope, "path": path, @@ -39,7 +41,7 @@ func (s *httpStorage) Read(c *models.ReqContext) response.Response { action := "Read" scope, path := getPathAndScope(c) - return response.JSON(200, map[string]string{ + return response.JSON(http.StatusOK, map[string]string{ "action": action, "scope": scope, "path": path, @@ -50,7 +52,7 @@ func (s *httpStorage) Delete(c *models.ReqContext) response.Response { action := "Delete" scope, path := getPathAndScope(c) - return response.JSON(200, map[string]string{ + return response.JSON(http.StatusOK, map[string]string{ "action": action, "scope": scope, "path": path, @@ -67,5 +69,5 @@ func (s *httpStorage) List(c *models.ReqContext) response.Response { if frame == nil { return response.Error(404, "not found", nil) } - return response.JSONStreaming(200, frame) + return response.JSONStreaming(http.StatusOK, frame) } diff --git a/pkg/services/thumbs/dummy.go b/pkg/services/thumbs/dummy.go index 6c984d412ad..769b70443a8 100644 --- a/pkg/services/thumbs/dummy.go +++ b/pkg/services/thumbs/dummy.go @@ -2,6 +2,7 @@ package thumbs import ( "context" + "net/http" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/models" @@ -39,19 +40,19 @@ func (ds *dummyService) GetDashboardPreviewsSetupSettings(c *models.ReqContext) func (ds *dummyService) StartCrawler(c *models.ReqContext) response.Response { result := make(map[string]string) result["error"] = "Not enabled" - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (ds *dummyService) StopCrawler(c *models.ReqContext) response.Response { result := make(map[string]string) result["error"] = "Not enabled" - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (ds *dummyService) CrawlerStatus(c *models.ReqContext) response.Response { result := make(map[string]string) result["error"] = "Not enabled" - return response.JSON(200, result) + return response.JSON(http.StatusOK, result) } func (ds *dummyService) Run(ctx context.Context) error { diff --git a/pkg/services/thumbs/service.go b/pkg/services/thumbs/service.go index 4b837baaaa3..45cba2828aa 100644 --- a/pkg/services/thumbs/service.go +++ b/pkg/services/thumbs/service.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "time" "github.com/grafana/grafana/pkg/api/response" @@ -192,7 +193,7 @@ func (hs *thumbService) UpdateThumbnailState(c *models.ReqContext) { } hs.log.Info("Updated dashboard thumbnail state", "dashboardUid", req.UID, "theme", req.Theme, "newState", body.State) - c.JSON(200, map[string]string{"success": "true"}) + c.JSON(http.StatusOK, map[string]string{"success": "true"}) } func (hs *thumbService) GetImage(c *models.ReqContext) { @@ -320,7 +321,7 @@ func (hs *thumbService) SetImage(c *models.ReqContext) { return } - c.JSON(200, map[string]int{"OK": len(fileBytes)}) + c.JSON(http.StatusOK, map[string]int{"OK": len(fileBytes)}) } func (hs *thumbService) StartCrawler(c *models.ReqContext) response.Response { @@ -348,7 +349,7 @@ func (hs *thumbService) StartCrawler(c *models.ReqContext) response.Response { return response.Error(500, "error starting", err) } - return response.JSON(200, status) + return response.JSON(http.StatusOK, status) } func (hs *thumbService) StopCrawler(c *models.ReqContext) response.Response { @@ -356,7 +357,7 @@ func (hs *thumbService) StopCrawler(c *models.ReqContext) response.Response { if err != nil { return response.Error(500, "error starting", err) } - return response.JSON(200, msg) + return response.JSON(http.StatusOK, msg) } func (hs *thumbService) CrawlerStatus(c *models.ReqContext) response.Response { @@ -364,7 +365,7 @@ func (hs *thumbService) CrawlerStatus(c *models.ReqContext) response.Response { if err != nil { return response.Error(500, "error starting", err) } - return response.JSON(200, msg) + return response.JSON(http.StatusOK, msg) } // Ideally this service would not require first looking up the full dashboard just to bet the id! diff --git a/pkg/tsdb/loki/framing_test.go b/pkg/tsdb/loki/framing_test.go index 78d8df2cfec..696cc5d3fb6 100644 --- a/pkg/tsdb/loki/framing_test.go +++ b/pkg/tsdb/loki/framing_test.go @@ -59,7 +59,7 @@ func TestSuccessResponse(t *testing.T) { bytes, err := os.ReadFile(responseFileName) require.NoError(t, err) - frames, err := runQuery(context.Background(), makeMockedAPI(200, "application/json", bytes), &test.query) + frames, err := runQuery(context.Background(), makeMockedAPI(http.StatusOK, "application/json", bytes), &test.query) require.NoError(t, err) dr := &backend.DataResponse{ diff --git a/pkg/tsdb/loki/loki_bench_test.go b/pkg/tsdb/loki/loki_bench_test.go index 331b8b533f1..de0b6d50a17 100644 --- a/pkg/tsdb/loki/loki_bench_test.go +++ b/pkg/tsdb/loki/loki_bench_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/rand" + "net/http" "strings" "testing" ) @@ -16,7 +17,7 @@ func BenchmarkMatrixJson(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - _, _ = runQuery(context.Background(), makeMockedAPI(200, "application/json", bytes), &lokiQuery{}) + _, _ = runQuery(context.Background(), makeMockedAPI(http.StatusOK, "application/json", bytes), &lokiQuery{}) } }