Skip auth for metrics
This commit is contained in:
parent
b8007500e7
commit
e9c46f5d5c
14
auth.go
14
auth.go
@ -7,6 +7,8 @@ import (
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
var skipPaths []string = []string{"/metrics"}
|
||||
|
||||
var configuredToken string
|
||||
|
||||
func init() {
|
||||
@ -17,14 +19,22 @@ func init() {
|
||||
// TokenMiddleware handles authentication
|
||||
func TokenMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// Skip selected paths
|
||||
var skip bool
|
||||
for _, path := range skipPaths {
|
||||
if path == c.Request().URL.Path {
|
||||
skip = true
|
||||
}
|
||||
}
|
||||
|
||||
tokenHeader := c.Request().Header.Get("Authorization")
|
||||
token := strings.Replace(tokenHeader, "Token ", "", -1)
|
||||
|
||||
if token == "" {
|
||||
if token == "" && !skip {
|
||||
token = c.QueryParam("token")
|
||||
}
|
||||
|
||||
if token != configuredToken || configuredToken == "" {
|
||||
if (token != configuredToken || configuredToken == "") && !skip {
|
||||
return c.JSONPretty(403, map[string]string{"message": "access denied"}, " ")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user