From cb78b018c0a01c847c8d39fb7f7b2b983a012872 Mon Sep 17 00:00:00 2001 From: Hayden Blauzvern Date: Tue, 8 Feb 2022 00:18:00 +0000 Subject: [PATCH] Fix linter errors Signed-off-by: Hayden Blauzvern --- pkg/cosign/tlog.go | 2 +- pkg/cosign/tuf/client_test.go | 2 +- pkg/cosign/tuf/status_type.go | 6 ++---- pkg/cosign/tuf/usage_type.go | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/cosign/tlog.go b/pkg/cosign/tlog.go index 83362f3ef754..bb380b7c9218 100644 --- a/pkg/cosign/tlog.go +++ b/pkg/cosign/tlog.go @@ -55,7 +55,7 @@ func GetRekorPubs(ctx context.Context) ([]*ecdsa.PublicKey, error) { if err != nil { return nil, err } - var publicKeys []*ecdsa.PublicKey + publicKeys := make([]*ecdsa.PublicKey, 0, len(targets)) for _, t := range targets { rekorPubKey, err := PemToECDSAKey(t.Target) if err != nil { diff --git a/pkg/cosign/tuf/client_test.go b/pkg/cosign/tuf/client_test.go index 056f9d3b5c95..87f7ff19931c 100644 --- a/pkg/cosign/tuf/client_test.go +++ b/pkg/cosign/tuf/client_test.go @@ -238,10 +238,10 @@ func TestGetTargetsByMeta(t *testing.T) { } tufObj, err := NewFromEnv(ctx) - defer tufObj.Close() if err != nil { t.Fatal(err) } + defer tufObj.Close() // Fetch a target with no custom metadata. targets, err := tufObj.GetTargetsByMeta(UnknownUsage, []string{"fooNoCustom.txt"}) if err != nil { diff --git a/pkg/cosign/tuf/status_type.go b/pkg/cosign/tuf/status_type.go index 4bed943fc71b..8a020e5d2310 100644 --- a/pkg/cosign/tuf/status_type.go +++ b/pkg/cosign/tuf/status_type.go @@ -17,8 +17,6 @@ package tuf import ( "fmt" "strings" - - "github.com/pkg/errors" ) type StatusKind int @@ -42,7 +40,7 @@ func (s StatusKind) String() string { func (s StatusKind) MarshalText() ([]byte, error) { str := s.String() if len(str) == 0 { - return nil, errors.New(fmt.Sprintf("error while marshalling, int(StatusKind)=%d not valid", int(s))) + return nil, fmt.Errorf("error while marshalling, int(StatusKind)=%d not valid", int(s)) } return []byte(s.String()), nil } @@ -56,7 +54,7 @@ func (s *StatusKind) UnmarshalText(text []byte) error { case "expired": *s = Expired default: - return errors.New(fmt.Sprintf("error while unmarshalling, StatusKind=%v not valid", string(text))) + return fmt.Errorf("error while unmarshalling, StatusKind=%v not valid", string(text)) } return nil } diff --git a/pkg/cosign/tuf/usage_type.go b/pkg/cosign/tuf/usage_type.go index 5a107286379b..4ea7ad04f2a3 100644 --- a/pkg/cosign/tuf/usage_type.go +++ b/pkg/cosign/tuf/usage_type.go @@ -17,8 +17,6 @@ package tuf import ( "fmt" "strings" - - "github.com/pkg/errors" ) type UsageKind int @@ -44,7 +42,7 @@ func (u UsageKind) String() string { func (u UsageKind) MarshalText() ([]byte, error) { str := u.String() if len(str) == 0 { - return nil, errors.New(fmt.Sprintf("error while marshalling, int(UsageKind)=%d not valid", int(u))) + return nil, fmt.Errorf("error while marshalling, int(UsageKind)=%d not valid", int(u)) } return []byte(u.String()), nil } @@ -60,7 +58,7 @@ func (u *UsageKind) UnmarshalText(text []byte) error { case "ctfe": *u = CTFE default: - return errors.New(fmt.Sprintf("error while unmarshalling, UsageKind=%v not valid", string(text))) + return fmt.Errorf("error while unmarshalling, UsageKind=%v not valid", string(text)) } return nil }