Skip to content

Commit

Permalink
more linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed May 21, 2024
1 parent fb7ec56 commit 89cd6c6
Show file tree
Hide file tree
Showing 32 changed files with 268 additions and 348 deletions.
2 changes: 1 addition & 1 deletion pkg/artifacts/signable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const (
var ignore = []cmp.Option{cmpopts.IgnoreUnexported(name.Registry{}, name.Repository{}, name.Digest{})}

func TestOCIArtifact_ExtractObjects(t *testing.T) {

tests := []struct {
name string
obj objects.TektonObject
Expand Down Expand Up @@ -808,6 +807,7 @@ func TestExtractBuildArtifactsFromResults(t *testing.T) {
}

func createDigest(t *testing.T, dgst string) name.Digest {
t.Helper()
result, err := name.NewDigest(dgst)
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/chains/formats/slsa/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions pkg/chains/formats/slsa/extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func TestSubjectDigestsAndRetrieveAllArtifactURIs(t *testing.T) {
t.Errorf("Wrong URIs extracted, diff=%s", diff)
}
}

})
}
}
Expand Down Expand Up @@ -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},
}),
Expand All @@ -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},
}),
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/chains/formats/slsa/extract/v1beta1/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func SubjectDigests(ctx context.Context, obj objects.TektonObject, slsaconfig *s
return subjects
}

// SubjectsFromPipelineRunV1Beta1 returns software artifacts produced from the PipelineRun object.
func SubjectsFromPipelineRunV1Beta1(ctx context.Context, obj objects.TektonObject, slsaconfig *slsaconfig.SlsaConfig) []*intoto.ResourceDescriptor {
prSubjects := SubjectsFromTektonObjectV1Beta1(ctx, obj)

Expand Down Expand Up @@ -90,6 +91,7 @@ func SubjectsFromPipelineRunV1Beta1(ctx context.Context, obj objects.TektonObjec
return result
}

// SubjectsFromTektonObjectV1Beta1 returns software artifacts produced from the Tekton object.
func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObject) []*intoto.ResourceDescriptor {
logger := logging.FromContext(ctx)
var subjects []*intoto.ResourceDescriptor
Expand Down
8 changes: 4 additions & 4 deletions pkg/chains/formats/slsa/extract/v1beta1/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}),
Expand All @@ -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},
}),
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ func TestUnsupportedBuildType(t *testing.T) {
if err == nil {
t.Error("getBuildDefinition(): expected error got nil")
}
if diff := cmp.Diff(slsa.BuildDefinition{}, got, protocmp.Transform()); diff != "" {
if diff := cmp.Diff(&slsa.BuildDefinition{}, &got, protocmp.Transform()); diff != "" {
t.Errorf("getBuildDefinition(): -want +got: %s", diff)
}
}

func getProtoStruct(t *testing.T, data map[string]any) *structpb.Struct {
t.Helper()
protoStruct, err := getStruct(data)
if err != nil {
t.Fatalf("error getting proto struct from data: %v", err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/chains/formats/slsa/internal/material/v1beta1/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/chains/formats/slsa/internal/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestMetadata(t *testing.T) {
tr := &v1.TaskRun{ //nolint:staticcheck
tr := &v1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "my-taskrun",
Namespace: "my-namespace",
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestMetadata(t *testing.T) {

func TestMetadataInTimeZone(t *testing.T) {
tz := time.FixedZone("Test Time", int((12 * time.Hour).Seconds()))
tr := &v1.TaskRun{ //nolint:staticcheck
tr := &v1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "my-taskrun",
Namespace: "my-namespace",
Expand Down
4 changes: 2 additions & 2 deletions pkg/chains/formats/slsa/internal/provenance/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func GetSLSA1Statement(obj objects.TektonObject, sub []*intoto.ResourceDescripto

func getProtoStruct(predicate *slsa.Provenance) (*structpb.Struct, error) {
protoStruct := &structpb.Struct{}
predicateJson, err := protojson.Marshal(predicate)
predicateJSON, err := protojson.Marshal(predicate)
if err != nil {
return nil, err
}

err = protojson.Unmarshal(predicateJson, protoStruct)
err = protojson.Unmarshal(predicateJSON, protoStruct)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (

// used to toggle the fields in see AddTektonTaskDescriptor
// and AddSLSATaskDescriptor
type addTaskDescriptorContent func(*objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error) //nolint:staticcheck
type addTaskDescriptorContent func(*objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error)

// ResolveOptions represents the configuration to be use to resolve dependencies.
type ResolveOptions struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func RemoveDuplicateResolvedDependencies(resolvedDependencies []*intoto.Resource

// AddTektonTaskDescriptor returns the more verbose resolved dependency content. this adds the name, uri, digest
// and content if possible.
func AddTektonTaskDescriptor(tr *objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error) { //nolint:staticcheck
func AddTektonTaskDescriptor(tr *objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error) {
rd := intoto.ResourceDescriptor{}
storedTr, err := json.Marshal(tr)
if err != nil {
Expand All @@ -130,7 +130,7 @@ func AddTektonTaskDescriptor(tr *objects.TaskRunObjectV1) (*intoto.ResourceDescr

// AddSLSATaskDescriptor resolves dependency content for the more generic slsa verifiers. just logs
// the name, uri and digest.
func AddSLSATaskDescriptor(tr *objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error) { //nolint:staticcheck
func AddSLSATaskDescriptor(tr *objects.TaskRunObjectV1) (*intoto.ResourceDescriptor, error) {
if tr.Status.Provenance != nil && tr.Status.Provenance.RefSource != nil {
return &intoto.ResourceDescriptor{
Name: PipelineTaskConfigName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func tektonTaskRuns() map[string][]byte {
func TestTaskRun(t *testing.T) {
tests := []struct {
name string
obj objects.TektonObject //nolint:staticcheck
obj objects.TektonObject
resolveOpts ResolveOptions
want []*intoto.ResourceDescriptor
}{
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestTaskRun(t *testing.T) {
},
{
name: "resolvedDependencies from remote task",
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{ //nolint:staticcheck
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{
Status: v1.TaskRunStatus{
TaskRunStatusFields: v1.TaskRunStatusFields{
Provenance: &v1.Provenance{
Expand All @@ -401,7 +401,7 @@ func TestTaskRun(t *testing.T) {
},
{
name: "git resolvedDependencies from taskrun params",
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{ //nolint:staticcheck
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{
Spec: v1.TaskRunSpec{
Params: []v1.Param{{
Name: "CHAINS-GIT_COMMIT",
Expand All @@ -424,7 +424,7 @@ func TestTaskRun(t *testing.T) {
},
{
name: "resolvedDependencies from step images",
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{ //nolint:staticcheck
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{
Status: v1.TaskRunStatus{
TaskRunStatusFields: v1.TaskRunStatusFields{
Steps: []v1.StepState{{
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestTaskRun(t *testing.T) {
},
{
name: "resolvedDependencies from step and sidecar images",
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{ //nolint:staticcheck
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{
Status: v1.TaskRunStatus{
TaskRunStatusFields: v1.TaskRunStatusFields{
Steps: []v1.StepState{{
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestTaskRun(t *testing.T) {
resolveOpts: ResolveOptions{
WithStepActionsResults: true,
},
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{ //nolint:staticcheck
obj: objects.NewTaskRunObjectV1(&v1.TaskRun{
Status: v1.TaskRunStatus{
TaskRunStatusFields: v1.TaskRunStatusFields{
Steps: []v1.StepState{{
Expand Down
1 change: 1 addition & 0 deletions pkg/chains/formats/slsa/internal/results/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestGetResultsWithoutBuildArtifacts(t *testing.T) {
}

func toJSONString(t *testing.T, val v1.ParamValue) []byte {
t.Helper()
res, err := json.Marshal(val)
if err != nil {
t.Fatalf("error converting to json string: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/chains/formats/slsa/v1/internal/protos/protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

// GetPredicateStruct returns a protobuf struct from the given SLSAv0.2 predicate.
func GetPredicateStruct(predicate *slsa.ProvenancePredicate) (*structpb.Struct, error) {
predicateJson, err := json.Marshal(predicate)
predicateJSON, err := json.Marshal(predicate)
if err != nil {
return nil, err
}

predicateStruct := &structpb.Struct{}
err = protojson.Unmarshal(predicateJson, predicateStruct)
err = protojson.Unmarshal(predicateJSON, predicateStruct)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 89cd6c6

Please sign in to comment.