mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service * Rename package to contextmodel * Generate ngalert files * Remove unused imports
This commit is contained in:
@@ -22,12 +22,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/plugincontext"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/comments/commentmodel"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -350,7 +350,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
CheckOrigin: checkOrigin,
|
||||
})
|
||||
|
||||
g.websocketHandler = func(ctx *models.ReqContext) {
|
||||
g.websocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
|
||||
// Centrifuge expects Credentials in context with a current user ID.
|
||||
@@ -363,7 +363,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
wsHandler.ServeHTTP(ctx.Resp, r)
|
||||
}
|
||||
|
||||
g.pushWebsocketHandler = func(ctx *models.ReqContext) {
|
||||
g.pushWebsocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
newCtx := livecontext.SetContextSignedUser(ctx.Req.Context(), user)
|
||||
newCtx = livecontext.SetContextStreamID(newCtx, web.Params(ctx.Req)[":streamId"])
|
||||
@@ -371,7 +371,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
pushWSHandler.ServeHTTP(ctx.Resp, r)
|
||||
}
|
||||
|
||||
g.pushPipelineWebsocketHandler = func(ctx *models.ReqContext) {
|
||||
g.pushPipelineWebsocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
newCtx := livecontext.SetContextSignedUser(ctx.Req.Context(), user)
|
||||
newCtx = livecontext.SetContextChannelID(newCtx, web.Params(ctx.Req)["*"])
|
||||
@@ -971,7 +971,7 @@ func (g *GrafanaLive) ClientCount(orgID int64, channel string) (int, error) {
|
||||
return len(p.Presence), nil
|
||||
}
|
||||
|
||||
func (g *GrafanaLive) HandleHTTPPublish(ctx *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleHTTPPublish(ctx *contextmodel.ReqContext) response.Response {
|
||||
cmd := dtos.LivePublishCmd{}
|
||||
if err := web.Bind(ctx.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -1047,7 +1047,7 @@ type streamChannelListResponse struct {
|
||||
}
|
||||
|
||||
// HandleListHTTP returns metadata so the UI can build a nice form
|
||||
func (g *GrafanaLive) HandleListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
var channels []*managedstream.ManagedChannel
|
||||
var err error
|
||||
if g.IsHA() {
|
||||
@@ -1065,7 +1065,7 @@ func (g *GrafanaLive) HandleListHTTP(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// HandleInfoHTTP special http response for
|
||||
func (g *GrafanaLive) HandleInfoHTTP(ctx *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleInfoHTTP(ctx *contextmodel.ReqContext) response.Response {
|
||||
path := web.Params(ctx.Req)["*"]
|
||||
if path == "grafana/dashboards/gitops" {
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
@@ -1078,7 +1078,7 @@ func (g *GrafanaLive) HandleInfoHTTP(ctx *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// HandleChannelRulesListHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
result, err := g.pipelineStorage.ListChannelRules(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get channel rules", err)
|
||||
@@ -1139,7 +1139,7 @@ func (s *DryRunRuleStorage) ListChannelRules(_ context.Context, _ int64) ([]pipe
|
||||
}
|
||||
|
||||
// HandlePipelineConvertTestHTTP ...
|
||||
func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1184,7 +1184,7 @@ func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) respon
|
||||
}
|
||||
|
||||
// HandleChannelRulesPostHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1204,7 +1204,7 @@ func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleChannelRulesPutHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1227,7 +1227,7 @@ func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// HandleChannelRulesDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1248,7 +1248,7 @@ func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *models.ReqContext) respons
|
||||
}
|
||||
|
||||
// HandlePipelineEntitiesListHTTP ...
|
||||
func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"subscribers": pipeline.SubscribersRegistry,
|
||||
"dataOutputs": pipeline.DataOutputsRegistry,
|
||||
@@ -1259,7 +1259,7 @@ func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *models.ReqContext) respo
|
||||
}
|
||||
|
||||
// HandleWriteConfigsListHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
backends, err := g.pipelineStorage.ListWriteConfigs(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get write configs", err)
|
||||
@@ -1274,7 +1274,7 @@ func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleWriteConfigsPostHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1294,7 +1294,7 @@ func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleWriteConfigsPutHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1338,7 +1338,7 @@ func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// HandleWriteConfigsDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsDeleteHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
"github.com/grafana/grafana/pkg/services/live/convert"
|
||||
"github.com/grafana/grafana/pkg/services/live/pushurl"
|
||||
@@ -45,7 +45,7 @@ func (g *Gateway) Run(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func (g *Gateway) Handle(ctx *models.ReqContext) {
|
||||
func (g *Gateway) Handle(ctx *contextmodel.ReqContext) {
|
||||
streamID := web.Params(ctx.Req)[":streamId"]
|
||||
|
||||
stream, err := g.GrafanaLive.ManagedStreamRunner.GetOrCreateStream(ctx.SignedInUser.OrgID, liveDto.ScopeStream, streamID)
|
||||
@@ -98,7 +98,7 @@ func (g *Gateway) Handle(ctx *models.ReqContext) {
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (g *Gateway) HandlePipelinePush(ctx *models.ReqContext) {
|
||||
func (g *Gateway) HandlePipelinePush(ctx *contextmodel.ReqContext) {
|
||||
channelID := web.Params(ctx.Req)["*"]
|
||||
|
||||
body, err := io.ReadAll(ctx.Req.Body)
|
||||
|
||||
Reference in New Issue
Block a user