Only enable debug endpoints if log level is debug or below (#1160)

This commit is contained in:
Anbraten 2022-09-03 20:48:53 +02:00 committed by GitHub
parent d5cdd2bb04
commit d8f598c2ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ package router
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/woodpecker-ci/woodpecker/server/api" "github.com/woodpecker-ci/woodpecker/server/api"
"github.com/woodpecker-ci/woodpecker/server/api/debug" "github.com/woodpecker-ci/woodpecker/server/api/debug"
@ -155,19 +156,21 @@ func apiRoutes(e *gin.Engine) {
secrets.DELETE("/:secret", api.DeleteGlobalSecret) secrets.DELETE("/:secret", api.DeleteGlobalSecret)
} }
debugger := e.Group("/api/debug") if zerolog.GlobalLevel() <= zerolog.DebugLevel {
{ debugger := e.Group("/api/debug")
debugger.Use(session.MustAdmin()) {
debugger.GET("/pprof/", debug.IndexHandler()) debugger.Use(session.MustAdmin())
debugger.GET("/pprof/heap", debug.HeapHandler()) debugger.GET("/pprof/", debug.IndexHandler())
debugger.GET("/pprof/goroutine", debug.GoroutineHandler()) debugger.GET("/pprof/heap", debug.HeapHandler())
debugger.GET("/pprof/block", debug.BlockHandler()) debugger.GET("/pprof/goroutine", debug.GoroutineHandler())
debugger.GET("/pprof/threadcreate", debug.ThreadCreateHandler()) debugger.GET("/pprof/block", debug.BlockHandler())
debugger.GET("/pprof/cmdline", debug.CmdlineHandler()) debugger.GET("/pprof/threadcreate", debug.ThreadCreateHandler())
debugger.GET("/pprof/profile", debug.ProfileHandler()) debugger.GET("/pprof/cmdline", debug.CmdlineHandler())
debugger.GET("/pprof/symbol", debug.SymbolHandler()) debugger.GET("/pprof/profile", debug.ProfileHandler())
debugger.POST("/pprof/symbol", debug.SymbolHandler()) debugger.GET("/pprof/symbol", debug.SymbolHandler())
debugger.GET("/pprof/trace", debug.TraceHandler()) debugger.POST("/pprof/symbol", debug.SymbolHandler())
debugger.GET("/pprof/trace", debug.TraceHandler())
}
} }
logLevel := e.Group("/api/log-level") logLevel := e.Group("/api/log-level")