1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

enable staticcheck QFxxxx rules (#34064)

This commit is contained in:
TheFox0x7
2025-03-29 22:32:28 +01:00
committed by GitHub
parent 5564c39105
commit 2a59dfbd47
47 changed files with 179 additions and 143 deletions

View File

@@ -162,8 +162,8 @@ func (r artifactV4Routes) buildSignature(endp, expires, artifactName string, tas
mac.Write([]byte(endp))
mac.Write([]byte(expires))
mac.Write([]byte(artifactName))
mac.Write([]byte(fmt.Sprint(taskID)))
mac.Write([]byte(fmt.Sprint(artifactID)))
fmt.Fprint(mac, taskID)
fmt.Fprint(mac, artifactID)
return mac.Sum(nil)
}

View File

@@ -46,13 +46,14 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
if ok { // it's a personal access token but not oauth2 token
scopeMatched := false
var err error
if accessMode == perm.AccessModeRead {
switch accessMode {
case perm.AccessModeRead:
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeReadPackage)
if err != nil {
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
return
}
} else if accessMode == perm.AccessModeWrite {
case perm.AccessModeWrite:
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeWritePackage)
if err != nil {
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
@@ -703,13 +704,14 @@ func ContainerRoutes() *web.Router {
g.MatchPath("POST", "/<image:*>/blobs/uploads", reqPackageAccess(perm.AccessModeWrite), container.VerifyImageName, container.InitiateUploadBlob)
g.MatchPath("GET", "/<image:*>/tags/list", container.VerifyImageName, container.GetTagList)
g.MatchPath("GET,PATCH,PUT,DELETE", `/<image:*>/blobs/uploads/<uuid:[-.=\w]+>`, reqPackageAccess(perm.AccessModeWrite), container.VerifyImageName, func(ctx *context.Context) {
if ctx.Req.Method == http.MethodGet {
switch ctx.Req.Method {
case http.MethodGet:
container.GetUploadBlob(ctx)
} else if ctx.Req.Method == http.MethodPatch {
case http.MethodPatch:
container.UploadBlob(ctx)
} else if ctx.Req.Method == http.MethodPut {
case http.MethodPut:
container.EndUploadBlob(ctx)
} else /* DELETE */ {
default: /* DELETE */
container.CancelUploadBlob(ctx)
}
})

View File

@@ -51,9 +51,10 @@ func ListHooks(ctx *context.APIContext) {
// for compatibility the default value is true
isSystemWebhook := optional.Some(true)
typeValue := ctx.FormString("type")
if typeValue == "default" {
switch typeValue {
case "default":
isSystemWebhook = optional.Some(false)
} else if typeValue == "all" {
case "all":
isSystemWebhook = optional.None[bool]()
}

View File

@@ -842,13 +842,13 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.APIC
func individualPermsChecker(ctx *context.APIContext) {
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
if ctx.ContextUser.IsIndividual() {
switch {
case ctx.ContextUser.Visibility == api.VisibleTypePrivate:
switch ctx.ContextUser.Visibility {
case api.VisibleTypePrivate:
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
ctx.APIErrorNotFound("Visit Project", nil)
return
}
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
case api.VisibleTypeLimited:
if ctx.Doer == nil {
ctx.APIErrorNotFound("Visit Project", nil)
return

View File

@@ -1103,8 +1103,8 @@ func DeleteArtifact(ctx *context.APIContext) {
func buildSignature(endp string, expires, artifactID int64) []byte {
mac := hmac.New(sha256.New, setting.GetGeneralTokenSigningSecret())
mac.Write([]byte(endp))
mac.Write([]byte(fmt.Sprint(expires)))
mac.Write([]byte(fmt.Sprint(artifactID)))
fmt.Fprint(mac, expires)
fmt.Fprint(mac, artifactID)
return mac.Sum(nil)
}

View File

@@ -24,9 +24,10 @@ import (
// appendPrivateInformation appends the owner and key type information to api.PublicKey
func appendPrivateInformation(ctx std_ctx.Context, apiKey *api.PublicKey, key *asymkey_model.PublicKey, defaultUser *user_model.User) (*api.PublicKey, error) {
if key.Type == asymkey_model.KeyTypeDeploy {
switch key.Type {
case asymkey_model.KeyTypeDeploy:
apiKey.KeyType = "deploy"
} else if key.Type == asymkey_model.KeyTypeUser {
case asymkey_model.KeyTypeUser:
apiKey.KeyType = "user"
if defaultUser.ID == key.OwnerID {
@@ -38,7 +39,7 @@ func appendPrivateInformation(ctx std_ctx.Context, apiKey *api.PublicKey, key *a
}
apiKey.Owner = convert.ToUser(ctx, user, user)
}
} else {
default:
apiKey.KeyType = "unknown"
}
apiKey.ReadOnly = key.Mode == perm.AccessModeRead