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

View File

@ -7,12 +7,11 @@ import (
"strconv"
"strings"
macaron "gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/middleware/cookies"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/web"
)
type AuthOptions struct {
@ -80,7 +79,7 @@ func EnsureEditorOrViewerCanEdit(c *models.ReqContext) {
}
}
func RoleAuth(roles ...models.RoleType) macaron.Handler {
func RoleAuth(roles ...models.RoleType) web.Handler {
return func(c *models.ReqContext) {
ok := false
for _, role := range roles {
@ -95,7 +94,7 @@ func RoleAuth(roles ...models.RoleType) macaron.Handler {
}
}
func Auth(options *AuthOptions) macaron.Handler {
func Auth(options *AuthOptions) web.Handler {
return func(c *models.ReqContext) {
forceLogin := false
if c.AllowAnonymous {
@ -134,7 +133,7 @@ func Auth(options *AuthOptions) macaron.Handler {
// feature flag is enabled.
// Intended for when feature flags open up access to APIs that
// are otherwise only available to admins.
func AdminOrFeatureEnabled(enabled bool) macaron.Handler {
func AdminOrFeatureEnabled(enabled bool) web.Handler {
return func(c *models.ReqContext) {
if c.OrgRole == models.ROLE_ADMIN {
return
@ -148,7 +147,7 @@ func AdminOrFeatureEnabled(enabled bool) macaron.Handler {
// SnapshotPublicModeOrSignedIn creates a middleware that allows access
// if snapshot public mode is enabled or if user is signed in.
func SnapshotPublicModeOrSignedIn(cfg *setting.Cfg) macaron.Handler {
func SnapshotPublicModeOrSignedIn(cfg *setting.Cfg) web.Handler {
return func(c *models.ReqContext) {
if cfg.SnapshotPublicMode {
return
@ -169,7 +168,7 @@ func ReqNotSignedIn(c *models.ReqContext) {
// NoAuth creates a middleware that doesn't require any authentication.
// If forceLogin param is set it will redirect the user to the login page.
func NoAuth() macaron.Handler {
func NoAuth() web.Handler {
return func(c *models.ReqContext) {
if shouldForceLogin(c) {
notAuthorized(c)