1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: enable noctx linter (#3888)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-05-11 14:04:40 +02:00 committed by GitHub
parent f67c138f54
commit 747f4128ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View file

@ -14,6 +14,7 @@ linters:
- govet
- importas
- ineffassign
- noctx
- staticcheck
- structcheck
- tenv

View file

@ -2,6 +2,7 @@ package common
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io/ioutil"
@ -22,7 +23,7 @@ import (
"github.com/kyverno/kyverno/pkg/autogen"
client "github.com/kyverno/kyverno/pkg/dclient"
"github.com/kyverno/kyverno/pkg/engine"
"github.com/kyverno/kyverno/pkg/engine/context"
engineContext "github.com/kyverno/kyverno/pkg/engine/context"
"github.com/kyverno/kyverno/pkg/engine/response"
ut "github.com/kyverno/kyverno/pkg/engine/utils"
"github.com/kyverno/kyverno/pkg/engine/variables"
@ -124,7 +125,13 @@ func GetPolicies(paths []string) (policies []v1.PolicyInterface, errors []error)
var fileBytes []byte
if isHTTPPath {
// We accept here that a random URL might be called based on user provided input.
resp, err := http.Get(path) // #nosec
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, path, nil)
if err != nil {
err := fmt.Errorf("failed to process %v: %v", path, err.Error())
errors = append(errors, err)
continue
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
err := fmt.Errorf("failed to process %v: %v", path, err.Error())
errors = append(errors, err)
@ -441,12 +448,12 @@ OuterLoop:
if err != nil {
log.Log.Error(err, "unable to convert raw resource to unstructured")
}
ctx := context.NewContext()
ctx := engineContext.NewContext()
if operationIsDelete {
err = context.AddOldResource(ctx, resourceRaw)
err = engineContext.AddOldResource(ctx, resourceRaw)
} else {
err = context.AddResource(ctx, resourceRaw)
err = engineContext.AddResource(ctx, resourceRaw)
}
if err != nil {
@ -466,7 +473,7 @@ OuterLoop:
}
}
if err := context.MutateResourceWithImageInfo(resourceRaw, ctx); err != nil {
if err := engineContext.MutateResourceWithImageInfo(resourceRaw, ctx); err != nil {
log.Log.Error(err, "failed to add image variables to context")
}
@ -541,7 +548,7 @@ OuterLoop:
ExcludeResourceFunc: func(s1, s2, s3 string) bool {
return false
},
JSONContext: context.NewContext(),
JSONContext: engineContext.NewContext(),
NamespaceLabels: namespaceLabels,
}
generateResponse := engine.ApplyBackgroundChecks(policyContext)

View file

@ -1,6 +1,7 @@
package common
import (
"context"
"errors"
"fmt"
"io/ioutil"
@ -216,7 +217,11 @@ func getFileBytes(path string) ([]byte, error) {
if IsHTTPRegex.MatchString(path) {
// We accept here that a random URL might be called based on user provided input.
resp, err := http.Get(path) // #nosec
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, path, nil)
if err != nil {
return nil, err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}

View file

@ -214,13 +214,17 @@ func CallAPI(request APIRequest) (*http.Response, error) {
var response *http.Response
switch request.Type {
case "GET":
resp, err := http.Get(request.URL)
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, request.URL, nil)
if err != nil {
return nil, fmt.Errorf("error occurred while calling %s: %w", request.URL, err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("error occurred while calling %s: %w", request.URL, err)
}
response = resp
case "POST", "PUT", "DELETE", "PATCH":
req, err := http.NewRequest(request.Type, request.URL, request.Body)
req, err := http.NewRequestWithContext(context.TODO(), request.Type, request.URL, request.Body)
if err != nil {
return nil, fmt.Errorf("error occurred while calling %s: %w", request.URL, err)
}