Enable golangci linter gomnd (#3171)

This commit is contained in:
Robert Kaussow
2024-03-15 18:00:25 +01:00
committed by GitHub
parent 9bbd30fa1e
commit a779eed3df
50 changed files with 262 additions and 176 deletions

View File

@@ -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)
}
}

View File

@@ -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()

View File

@@ -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()