Chore: replace macaron with web package (#40136)

* replace macaron with web package

* add web.go
This commit is contained in:
Serge Zaitsev
2021-10-11 14:30:59 +02:00
committed by GitHub
parent 78ebac0116
commit 57fcfd578d
70 changed files with 369 additions and 375 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"github.com/grafana/grafana/pkg/services/ngalert/store"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/web"
)
const (
@@ -178,7 +178,7 @@ func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext) response.Res
return errResp
}
silenceID := macaron.Params(c.Req)[":SilenceId"]
silenceID := web.Params(c.Req)[":SilenceId"]
if err := am.DeleteSilence(silenceID); err != nil {
if errors.Is(err, notifier.ErrSilenceNotFound) {
return ErrResp(http.StatusNotFound, err, "")
@@ -305,7 +305,7 @@ func (srv AlertmanagerSrv) RouteGetSilence(c *models.ReqContext) response.Respon
return errResp
}
silenceID := macaron.Params(c.Req)[":SilenceId"]
silenceID := web.Params(c.Req)[":SilenceId"]
gettableSilence, err := am.GetSilence(silenceID)
if err != nil {
if errors.Is(err, notifier.ErrSilenceNotFound) {
+12 -13
View File
@@ -6,19 +6,18 @@ import (
"net/http"
"time"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/ngalert/state"
"github.com/grafana/grafana/pkg/services/ngalert/store"
"github.com/grafana/grafana/pkg/services/quota"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/api/apierrors"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/datasources"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/services/ngalert/state"
"github.com/grafana/grafana/pkg/services/ngalert/store"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
"github.com/prometheus/common/model"
)
@@ -31,7 +30,7 @@ type RulerSrv struct {
}
func (srv RulerSrv) RouteDeleteNamespaceRulesConfig(c *models.ReqContext) response.Response {
namespaceTitle := macaron.Params(c.Req)[":Namespace"]
namespaceTitle := web.Params(c.Req)[":Namespace"]
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgId, c.SignedInUser, true)
if err != nil {
return toNamespaceErrorResponse(err)
@@ -50,12 +49,12 @@ func (srv RulerSrv) RouteDeleteNamespaceRulesConfig(c *models.ReqContext) respon
}
func (srv RulerSrv) RouteDeleteRuleGroupConfig(c *models.ReqContext) response.Response {
namespaceTitle := macaron.Params(c.Req)[":Namespace"]
namespaceTitle := web.Params(c.Req)[":Namespace"]
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgId, c.SignedInUser, true)
if err != nil {
return toNamespaceErrorResponse(err)
}
ruleGroup := macaron.Params(c.Req)[":Groupname"]
ruleGroup := web.Params(c.Req)[":Groupname"]
uids, err := srv.store.DeleteRuleGroupAlertRules(c.SignedInUser.OrgId, namespace.Uid, ruleGroup)
if err != nil {
@@ -73,7 +72,7 @@ func (srv RulerSrv) RouteDeleteRuleGroupConfig(c *models.ReqContext) response.Re
}
func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext) response.Response {
namespaceTitle := macaron.Params(c.Req)[":Namespace"]
namespaceTitle := web.Params(c.Req)[":Namespace"]
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgId, c.SignedInUser, false)
if err != nil {
return toNamespaceErrorResponse(err)
@@ -114,13 +113,13 @@ func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext) response.
}
func (srv RulerSrv) RouteGetRulegGroupConfig(c *models.ReqContext) response.Response {
namespaceTitle := macaron.Params(c.Req)[":Namespace"]
namespaceTitle := web.Params(c.Req)[":Namespace"]
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgId, c.SignedInUser, false)
if err != nil {
return toNamespaceErrorResponse(err)
}
ruleGroup := macaron.Params(c.Req)[":Groupname"]
ruleGroup := web.Params(c.Req)[":Groupname"]
q := ngmodels.ListRuleGroupAlertRulesQuery{
OrgID: c.SignedInUser.OrgId,
NamespaceUID: namespace.Uid,
@@ -225,7 +224,7 @@ func (srv RulerSrv) RouteGetRulesConfig(c *models.ReqContext) response.Response
}
func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConfig apimodels.PostableRuleGroupConfig) response.Response {
namespaceTitle := macaron.Params(c.Req)[":Namespace"]
namespaceTitle := web.Params(c.Req)[":Namespace"]
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgId, c.SignedInUser, true)
if err != nil {
return toNamespaceErrorResponse(err)
+2 -2
View File
@@ -15,7 +15,7 @@ import (
"github.com/grafana/grafana/pkg/services/ngalert/eval"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/web"
)
type TestingApiSrv struct {
@@ -27,7 +27,7 @@ type TestingApiSrv struct {
}
func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
recipient := macaron.Params(c.Req)[":Recipient"]
recipient := web.Params(c.Req)[":Recipient"]
if recipient == apimodels.GrafanaBackend.String() {
if body.Type() != apimodels.GrafanaBackend || body.GrafanaManagedCondition == nil {
return ErrResp(http.StatusBadRequest, errors.New("unexpected payload"), "")
+3 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/web"
"gopkg.in/yaml.v3"
)
@@ -140,7 +140,7 @@ func (am *LotexAM) RouteDeleteSilence(ctx *models.ReqContext) response.Response
ctx,
http.MethodDelete,
"silence",
[]string{macaron.Params(ctx.Req)[":SilenceId"]},
[]string{web.Params(ctx.Req)[":SilenceId"]},
nil,
messageExtractor,
nil,
@@ -188,7 +188,7 @@ func (am *LotexAM) RouteGetSilence(ctx *models.ReqContext) response.Response {
ctx,
http.MethodGet,
"silence",
[]string{macaron.Params(ctx.Req)[":SilenceId"]},
[]string{web.Params(ctx.Req)[":SilenceId"]},
nil,
jsonExtractor(&apimodels.GettableSilence{}),
nil,
+8 -8
View File
@@ -7,7 +7,7 @@ import (
"net/url"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/web"
"gopkg.in/yaml.v3"
"github.com/grafana/grafana/pkg/api/response"
@@ -42,7 +42,7 @@ func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) res
http.MethodDelete,
withPath(
*ctx.Req.URL,
fmt.Sprintf("%s/%s", legacyRulerPrefix, macaron.Params(ctx.Req)[":Namespace"]),
fmt.Sprintf("%s/%s", legacyRulerPrefix, web.Params(ctx.Req)[":Namespace"]),
),
nil,
messageExtractor,
@@ -63,8 +63,8 @@ func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext) response
fmt.Sprintf(
"%s/%s/%s",
legacyRulerPrefix,
macaron.Params(ctx.Req)[":Namespace"],
macaron.Params(ctx.Req)[":Groupname"],
web.Params(ctx.Req)[":Namespace"],
web.Params(ctx.Req)[":Groupname"],
),
),
nil,
@@ -86,7 +86,7 @@ func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext) respon
fmt.Sprintf(
"%s/%s",
legacyRulerPrefix,
macaron.Params(ctx.Req)[":Namespace"],
web.Params(ctx.Req)[":Namespace"],
),
),
nil,
@@ -108,8 +108,8 @@ func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *models.ReqContext) response.R
fmt.Sprintf(
"%s/%s/%s",
legacyRulerPrefix,
macaron.Params(ctx.Req)[":Namespace"],
macaron.Params(ctx.Req)[":Groupname"],
web.Params(ctx.Req)[":Namespace"],
web.Params(ctx.Req)[":Groupname"],
),
),
nil,
@@ -145,7 +145,7 @@ func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimo
if err != nil {
return ErrResp(500, err, "Failed marshal rule group")
}
ns := macaron.Params(ctx.Req)[":Namespace"]
ns := web.Params(ctx.Req)[":Namespace"]
u := withPath(*ctx.Req.URL, fmt.Sprintf("%s/%s", legacyRulerPrefix, ns))
return r.withReq(ctx, http.MethodPost, u, bytes.NewBuffer(yml), jsonExtractor(nil), nil)
}
+3 -3
View File
@@ -23,8 +23,8 @@ import (
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
"github.com/pkg/errors"
"gopkg.in/macaron.v1"
"gopkg.in/yaml.v3"
)
@@ -40,7 +40,7 @@ func toMacaronPath(path string) string {
}
func backendType(ctx *models.ReqContext, cache datasources.CacheService) (apimodels.Backend, error) {
recipient := macaron.Params(ctx.Req)[":Recipient"]
recipient := web.Params(ctx.Req)[":Recipient"]
if recipient == apimodels.GrafanaBackend.String() {
return apimodels.GrafanaBackend, nil
}
@@ -77,7 +77,7 @@ func replacedResponseWriter(ctx *models.ReqContext) (*models.ReqContext, *respon
resp := response.CreateNormalResponse(make(http.Header), nil, 0)
cpy := *ctx
cpyMCtx := *cpy.Context
cpyMCtx.Resp = macaron.NewResponseWriter(ctx.Req.Method, &safeMacaronWrapper{resp})
cpyMCtx.Resp = web.NewResponseWriter(ctx.Req.Method, &safeMacaronWrapper{resp})
cpy.Context = &cpyMCtx
return &cpy, resp
}