From 9339b2cd05b68c8646745b6a8cfcba49f080d1a3 Mon Sep 17 00:00:00 2001 From: Renzo Rojas Silva Date: Mon, 20 May 2024 23:48:01 -0400 Subject: [PATCH] more linter errors from local run --- pkg/chains/formats/slsa/extract/extract.go | 3 ++- pkg/chains/formats/slsa/extract/extract_test.go | 9 ++++----- .../formats/slsa/extract/v1beta1/extract_test.go | 8 ++++---- .../formats/slsa/internal/material/v1beta1/material.go | 6 ++++-- pkg/chains/formats/slsa/v2alpha3/slsav2_test.go | 7 ++----- pkg/chains/formats/slsa/v2alpha4/slsav2.go | 2 +- pkg/chains/storage/grafeas/grafeas_test.go | 10 ++++------ pkg/chains/storage/tekton/tekton.go | 4 ++-- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pkg/chains/formats/slsa/extract/extract.go b/pkg/chains/formats/slsa/extract/extract.go index bedd787a42..a47d558f7c 100644 --- a/pkg/chains/formats/slsa/extract/extract.go +++ b/pkg/chains/formats/slsa/extract/extract.go @@ -77,7 +77,8 @@ func subjectsFromPipelineRun(ctx context.Context, obj objects.TektonObject, slsa pSpec := pro.Status.PipelineSpec if pSpec != nil { - pipelineTasks := append(pSpec.Tasks, pSpec.Finally...) + pipelineTasks := pSpec.Tasks + pipelineTasks = append(pipelineTasks, pSpec.Finally...) for _, t := range pipelineTasks { tr := pro.GetTaskRunFromTask(t.Name) // Ignore Tasks that did not execute during the PipelineRun. diff --git a/pkg/chains/formats/slsa/extract/extract_test.go b/pkg/chains/formats/slsa/extract/extract_test.go index 3e94989a54..6467087466 100644 --- a/pkg/chains/formats/slsa/extract/extract_test.go +++ b/pkg/chains/formats/slsa/extract/extract_test.go @@ -120,7 +120,6 @@ func TestSubjectDigestsAndRetrieveAllArtifactURIs(t *testing.T) { t.Errorf("Wrong URIs extracted, diff=%s", diff) } } - }) } } @@ -209,7 +208,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) { { name: "deep inspection enabled: pipelinerun and taskrun have duplicated results", pro: createProWithTaskRunResults( - createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1), + createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}), []artifact{ {uri: artifactURL1, digest: "sha256:" + artifactDigest1}, }), @@ -229,7 +228,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) { { name: "deep inspection enabled: pipelinerun and taskrun have different results", pro: createProWithTaskRunResults( - createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1), + createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}), []artifact{ {uri: artifactURL2, digest: "sha256:" + artifactDigest2}, }), @@ -441,7 +440,7 @@ func TestSubjectsFromBuildArtifact(t *testing.T) { } } -func createTaskRunObjectWithResults(results map[string]string) objects.TektonObject { +func createTaskRunObjectWithResults(results map[string]string) *objects.TaskRunObjectV1 { trResults := []v1.TaskRunResult{} prefix := 0 for url, digest := range results { @@ -463,7 +462,7 @@ func createTaskRunObjectWithResults(results map[string]string) objects.TektonObj ) } -func createProWithPipelineResults(results map[string]string) objects.TektonObject { +func createProWithPipelineResults(results map[string]string) *objects.PipelineRunObjectV1 { prResults := []v1.PipelineRunResult{} prefix := 0 for url, digest := range results { diff --git a/pkg/chains/formats/slsa/extract/v1beta1/extract_test.go b/pkg/chains/formats/slsa/extract/v1beta1/extract_test.go index 8f8e2b9743..9eb1a371b9 100644 --- a/pkg/chains/formats/slsa/extract/v1beta1/extract_test.go +++ b/pkg/chains/formats/slsa/extract/v1beta1/extract_test.go @@ -209,7 +209,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) { { name: "deep inspection enabled: pipelinerun and taskrun have duplicated results", pro: createProWithTaskRunResults( - createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1Beta1), + createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}), []artifact{ {uri: artifactURL1, digest: "sha256:" + artifactDigest1}, }), @@ -229,7 +229,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) { { name: "deep inspection enabled: pipelinerun and taskrun have different results", pro: createProWithTaskRunResults( - createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}).(*objects.PipelineRunObjectV1Beta1), + createProWithPipelineResults(map[string]string{artifactURL1: "sha256:" + artifactDigest1}), []artifact{ {uri: artifactURL2, digest: "sha256:" + artifactDigest2}, }), @@ -272,7 +272,7 @@ func TestPipelineRunObserveModeForSubjects(t *testing.T) { } } -func createTaskRunObjectV1Beta1WithResults(results map[string]string) objects.TektonObject { +func createTaskRunObjectV1Beta1WithResults(results map[string]string) *objects.TaskRunObjectV1Beta1 { trResults := []v1beta1.TaskRunResult{} prefix := 0 for url, digest := range results { @@ -294,7 +294,7 @@ func createTaskRunObjectV1Beta1WithResults(results map[string]string) objects.Te ) } -func createProWithPipelineResults(results map[string]string) objects.TektonObject { +func createProWithPipelineResults(results map[string]string) *objects.PipelineRunObjectV1Beta1 { prResults := []v1beta1.PipelineRunResult{} prefix := 0 for url, digest := range results { diff --git a/pkg/chains/formats/slsa/internal/material/v1beta1/material.go b/pkg/chains/formats/slsa/internal/material/v1beta1/material.go index ef49f2b73c..650bb1d6dd 100644 --- a/pkg/chains/formats/slsa/internal/material/v1beta1/material.go +++ b/pkg/chains/formats/slsa/internal/material/v1beta1/material.go @@ -74,7 +74,8 @@ func PipelineMaterials(ctx context.Context, pro *objects.PipelineRunObjectV1Beta } pSpec := pro.Status.PipelineSpec if pSpec != nil { - pipelineTasks := append(pSpec.Tasks, pSpec.Finally...) + pipelineTasks := pSpec.Tasks + pipelineTasks = append(pipelineTasks, pSpec.Finally...) for _, t := range pipelineTasks { tr := pro.GetTaskRunFromTask(t.Name) // Ignore Tasks that did not execute during the PipelineRun. @@ -269,7 +270,8 @@ func FromPipelineParamsAndResults(ctx context.Context, pro *objects.PipelineRunO // search type hinting param/results from each individual taskruns if slsaconfig.DeepInspectionEnabled { logger := logging.FromContext(ctx) - pipelineTasks := append(pSpec.Tasks, pSpec.Finally...) + pipelineTasks := pSpec.Tasks + pipelineTasks = append(pipelineTasks, pSpec.Finally...) for _, t := range pipelineTasks { tr := pro.GetTaskRunFromTask(t.Name) // Ignore Tasks that did not execute during the PipelineRun. diff --git a/pkg/chains/formats/slsa/v2alpha3/slsav2_test.go b/pkg/chains/formats/slsa/v2alpha3/slsav2_test.go index c03913276d..6d1de44767 100644 --- a/pkg/chains/formats/slsa/v2alpha3/slsav2_test.go +++ b/pkg/chains/formats/slsa/v2alpha3/slsav2_test.go @@ -80,13 +80,10 @@ func TestCreatePayloadError(t *testing.T) { } if err == nil { t.Errorf("Expected error") - } else { - if err.Error() != "intoto does not support type: not a task ref" { - t.Errorf("wrong error returned: '%s'", err.Error()) - } + } else if err.Error() != "intoto does not support type: not a task ref" { + t.Errorf("wrong error returned: '%s'", err.Error()) } }) - } func TestCorrectPayloadType(t *testing.T) { diff --git a/pkg/chains/formats/slsa/v2alpha4/slsav2.go b/pkg/chains/formats/slsa/v2alpha4/slsav2.go index 6080df5119..3db3fbeeff 100644 --- a/pkg/chains/formats/slsa/v2alpha4/slsav2.go +++ b/pkg/chains/formats/slsa/v2alpha4/slsav2.go @@ -42,7 +42,7 @@ type Slsa struct { } // NewFormatter returns a new v2alpha4 payloader. -func NewFormatter(cfg config.Config) (formats.Payloader, error) { +func NewFormatter(cfg config.Config) (formats.Payloader, error) { //nolint:ireturn return &Slsa{ slsaConfig: &slsaconfig.SlsaConfig{ BuilderID: cfg.Builder.ID, diff --git a/pkg/chains/storage/grafeas/grafeas_test.go b/pkg/chains/storage/grafeas/grafeas_test.go index 253cd332ea..57809aee31 100644 --- a/pkg/chains/storage/grafeas/grafeas_test.go +++ b/pkg/chains/storage/grafeas/grafeas_test.go @@ -302,7 +302,7 @@ func TestGrafeasBackend_StoreAndRetrieve(t *testing.T) { wantErr: false, }, { - name: "intoto for the ci pipeline, no error, 2 occurences should be created for the pipelinerun for the 2 artifact generated.", + name: "intoto for the ci pipeline, no error, 2 occurrences should be created for the pipelinerun for the 2 artifact generated.", args: args{ runObject: &objects.PipelineRunObjectV1Beta1{ PipelineRun: ciPipeline, @@ -337,10 +337,9 @@ func TestGrafeasBackend_StoreAndRetrieve(t *testing.T) { } defer conn.Close() - // collect all the occurences expected to be created in the server + // collect all the occurrences expected to be created in the server allOccurrencesInServer := []*pb.Occurrence{} for _, test := range tests { - // run the test t.Run(test.name, func(t *testing.T) { ctx := logging.WithLogger(ctx, logtesting.TestLogger(t)) @@ -573,7 +572,7 @@ func getRawPayload(t *testing.T, in interface{}) []byte { // set up the connection between grafeas server and client // and return the client object to the caller -func setupConnection() (*grpc.ClientConn, pb.GrafeasClient, error) { +func setupConnection() (*grpc.ClientConn, pb.GrafeasClient, error) { //nolint:ireturn serv := grpc.NewServer() pb.RegisterGrafeasServer(serv, &mockGrafeasServer{}) @@ -627,7 +626,7 @@ func (s *mockGrafeasServer) CreateOccurrence(ctx context.Context, req *pb.Create occ := req.GetOccurrence() noteName := req.GetOccurrence().NoteName resourceUri := req.GetOccurrence().ResourceUri - occ.Name = resourceUri // mock how the occurrence ID (name) is outputed. + occ.Name = resourceUri // mock how the occurrence ID (name) is outputted. if note, ok := s.entries[noteName]; ok { if _, ok := note.occurrences[resourceUri]; ok { @@ -714,7 +713,6 @@ func (s *mockGrafeasServer) getOccurrencesByFilter(filter string, occurrences [] // mock how uri filter works uris := parseURIFilterString(filter) - // result result result := []*pb.Occurrence{} for _, occ := range occurrences { diff --git a/pkg/chains/storage/tekton/tekton.go b/pkg/chains/storage/tekton/tekton.go index fcb5da97e1..f3a7b9c46d 100644 --- a/pkg/chains/storage/tekton/tekton.go +++ b/pkg/chains/storage/tekton/tekton.go @@ -89,7 +89,7 @@ func (b *Backend) retrieveAnnotationValue(ctx context.Context, obj objects.Tekto var annotationValue string annotations, err := obj.GetLatestAnnotations(ctx, b.pipelineclientset) if err != nil { - return "", fmt.Errorf("error retrieving the annotation value for the key %q: %s", annotationKey, err) + return "", fmt.Errorf("error retrieving the annotation value for the key %q: %w", annotationKey, err) } val, ok := annotations[annotationKey] @@ -99,7 +99,7 @@ func (b *Backend) retrieveAnnotationValue(ctx context.Context, obj objects.Tekto if decode { decodedAnnotation, err := base64.StdEncoding.DecodeString(val) if err != nil { - return "", fmt.Errorf("error decoding the annotation value for the key %q: %s", annotationKey, err) + return "", fmt.Errorf("error decoding the annotation value for the key %q: %w", annotationKey, err) } annotationValue = string(decodedAnnotation) } else {