fix status code 200 (#47818)

This commit is contained in:
ying-jeanne 2022-04-15 14:01:58 +02:00 committed by GitHub
parent f263cad8ab
commit 7ddae870e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 166 additions and 152 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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,
})
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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/*

View File

@ -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,

View File

@ -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,

View File

@ -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.

View File

@ -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) {

View File

@ -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.

View File

@ -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)

View File

@ -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)
}

View File

@ -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,
})

View File

@ -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

View File

@ -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}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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.

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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)
}

View File

@ -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

View File

@ -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",
})
}

View File

@ -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 {

View File

@ -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",
})
}

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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.

View File

@ -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 {

View File

@ -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),
})
}

View File

@ -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) {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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!

View File

@ -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{

View File

@ -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{})
}
}