mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-19 09:44:48 +00:00
Enable golangci linter gomnd (#3171)
This commit is contained in:
@@ -42,7 +42,7 @@ func Options(c *gin.Context) {
|
||||
c.Header("Access-Control-Allow-Headers", "authorization, origin, content-type, accept")
|
||||
c.Header("Allow", "HEAD,GET,POST,PUT,PATCH,DELETE,OPTIONS")
|
||||
c.Header("Content-Type", "application/json")
|
||||
c.AbortWithStatus(200)
|
||||
c.AbortWithStatus(http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,8 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go.woodpecker-ci.org/woodpecker/v2/shared/token"
|
||||
@@ -25,7 +27,7 @@ import (
|
||||
func AuthorizeAgent(c *gin.Context) {
|
||||
secret, _ := c.MustGet("agent").(string)
|
||||
if secret == "" {
|
||||
c.String(401, "invalid or empty token.")
|
||||
c.String(http.StatusUnauthorized, "invalid or empty token.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,10 +36,10 @@ func AuthorizeAgent(c *gin.Context) {
|
||||
})
|
||||
switch {
|
||||
case err != nil:
|
||||
c.String(500, "invalid or empty token. %s", err)
|
||||
c.String(http.StatusInternalServerError, "invalid or empty token. %s", err)
|
||||
c.Abort()
|
||||
case parsed.Kind != token.AgentToken:
|
||||
c.String(403, "invalid token. please use an agent token")
|
||||
c.String(http.StatusForbidden, "invalid token. please use an agent token")
|
||||
c.Abort()
|
||||
default:
|
||||
c.Next()
|
||||
|
@@ -75,10 +75,10 @@ func MustAdmin() gin.HandlerFunc {
|
||||
user := User(c)
|
||||
switch {
|
||||
case user == nil:
|
||||
c.String(401, "User not authorized")
|
||||
c.String(http.StatusUnauthorized, "User not authorized")
|
||||
c.Abort()
|
||||
case !user.Admin:
|
||||
c.String(403, "User not authorized")
|
||||
c.String(http.StatusForbidden, "User not authorized")
|
||||
c.Abort()
|
||||
default:
|
||||
c.Next()
|
||||
@@ -92,10 +92,10 @@ func MustRepoAdmin() gin.HandlerFunc {
|
||||
perm := Perm(c)
|
||||
switch {
|
||||
case user == nil:
|
||||
c.String(401, "User not authorized")
|
||||
c.String(http.StatusUnauthorized, "User not authorized")
|
||||
c.Abort()
|
||||
case !perm.Admin:
|
||||
c.String(403, "User not authorized")
|
||||
c.String(http.StatusForbidden, "User not authorized")
|
||||
c.Abort()
|
||||
default:
|
||||
c.Next()
|
||||
@@ -108,7 +108,7 @@ func MustUser() gin.HandlerFunc {
|
||||
user := User(c)
|
||||
switch {
|
||||
case user == nil:
|
||||
c.String(401, "User not authorized")
|
||||
c.String(http.StatusUnauthorized, "User not authorized")
|
||||
c.Abort()
|
||||
default:
|
||||
c.Next()
|
||||
|
Reference in New Issue
Block a user