Skip to content

Commit

Permalink
fix lints, update errors
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Mar 3, 2024
1 parent a20935f commit 2da64d6
Show file tree
Hide file tree
Showing 44 changed files with 127 additions and 112 deletions.
10 changes: 5 additions & 5 deletions cmd/backfill-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ func main() {
// uuid is the global UUID - tree ID and entry UUID
e, _, _, err := unmarshalEntryImpl(entry.Body.(string))
if err != nil {
parseErrs = append(parseErrs, fmt.Errorf("error unmarshalling entry for %s: %v", uuid, err))
parseErrs = append(parseErrs, fmt.Errorf("error unmarshalling entry for %s: %w", uuid, err))
continue
}
keys, err := e.IndexKeys()
if err != nil {
parseErrs = append(parseErrs, fmt.Errorf("error building index keys for %s: %v", uuid, err))
parseErrs = append(parseErrs, fmt.Errorf("error building index keys for %s: %w", uuid, err))
continue
}
for _, key := range keys {
// remove the key-value pair from the index in case it already exists
if err := removeFromIndex(ctx, redisClient, key, uuid); err != nil {
insertErrs = append(insertErrs, fmt.Errorf("error removing UUID %s with key %s: %v", uuid, key, err))
insertErrs = append(insertErrs, fmt.Errorf("error removing UUID %s with key %s: %w", uuid, key, err))
}
if err := addToIndex(ctx, redisClient, key, uuid); err != nil {
insertErrs = append(insertErrs, fmt.Errorf("error inserting UUID %s with key %s: %v", uuid, key, err))
insertErrs = append(insertErrs, fmt.Errorf("error inserting UUID %s with key %s: %w", uuid, key, err))
}
fmt.Printf("Uploaded Redis entry %s, index %d, key %s\n", uuid, index, key)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func redisClient() *redis.Client {
// #nosec G402
if *enableTLS {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: *insecureSkipVerify,
InsecureSkipVerify: *insecureSkipVerify, //nolint: gosec
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/format/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CobraCmd func(cmd *cobra.Command, args []string)
type formatCmd func(args []string) (interface{}, error)

func WrapCmd(f formatCmd) CobraCmd {
return func(cmd *cobra.Command, args []string) {
return func(_ *cobra.Command, args []string) {
obj, err := f(args)
if err != nil {
log.CliLogger.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/rekor-cli/app/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ var getCmd = &cobra.Command{
Use: "get",
Short: "Rekor get command",
Long: `Get information regarding entries in the transparency log`,
PreRun: func(cmd *cobra.Command, args []string) {
PreRun: func(cmd *cobra.Command, _ []string) {
// these are bound here so that they are not overwritten by other commands
if err := viper.BindPFlags(cmd.Flags()); err != nil {
log.CliLogger.Fatal("Error initializing cmd line args: ", err)
log.CliLogger.Fatalf("Error initializing cmd line args: %w", err)
}
},
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
ctx := context.Background()
rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log.CliLogger))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/log_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var logInfoCmd = &cobra.Command{
Use: "loginfo",
Short: "Rekor loginfo command",
Long: `Prints info about the transparency log`,
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
serverURL := viper.GetString("rekor_server")
ctx := context.Background()
rekorClient, err := client.GetRekorClient(serverURL, client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log.CliLogger))
Expand Down
6 changes: 3 additions & 3 deletions cmd/rekor-cli/app/log_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ var logProofCmd = &cobra.Command{
Use: "logproof",
Short: "Rekor logproof command",
Long: `Prints information required to compute the consistency proof of the transparency log`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
// these are bound here so that they are not overwritten by other commands
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return fmt.Errorf("error initializing cmd line args: %s", err)
return fmt.Errorf("error initializing cmd line args: %w", err)
}
if viper.GetUint64("first-size") == 0 {
return errors.New("first-size must be > 0")
Expand All @@ -72,7 +72,7 @@ var logProofCmd = &cobra.Command{
}
return nil
},
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log.CliLogger))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var rootCmd = &cobra.Command{
Use: "rekor-cli",
Short: "Rekor CLI",
Long: `Rekor command line interface tool`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
return initConfig(cmd)
},
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/rekor-cli/app/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ var searchCmd = &cobra.Command{
Use: "search",
Short: "Rekor search command",
Long: `Searches the Rekor index to find entries by sha, artifact, public key, or e-mail`,
PreRun: func(cmd *cobra.Command, args []string) {
PreRun: func(cmd *cobra.Command, _ []string) {
// these are bound here so that they are not overwritten by other commands
if err := viper.BindPFlags(cmd.Flags()); err != nil {
log.CliLogger.Fatal("Error initializing cmd line args: ", err)
log.CliLogger.Fatalf("Error initializing cmd line args: %w", err)
}
if err := validateSearchPFlags(); err != nil {
log.CliLogger.Error(err)
_ = cmd.Help()
os.Exit(1)
}
},
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
log := log.CliLogger
rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rekor-cli/app/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func (u *uploadCmdOutput) String() string {
var uploadCmd = &cobra.Command{
Use: "upload",
Short: "Upload an artifact to Rekor",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
// these are bound here so that they are not overwritten by other commands
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return validateArtifactPFlags(false, false)
},
Long: `This command takes the public key, signature and URL of the release artifact and uploads it to the rekor server.`,
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
ctx := context.Background()
rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log.CliLogger))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/rekor-cli/app/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ var verifyCmd = &cobra.Command{
Use: "verify",
Short: "Rekor verify command",
Long: `Verifies an entry exists in the transparency log through an inclusion proof`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
// these are bound here so that they are not overwritten by other commands
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return fmt.Errorf("error initializing cmd line args: %s", err)
return fmt.Errorf("error initializing cmd line args: %w", err)
}
return validateArtifactPFlags(true, true)
},
Run: format.WrapCmd(func(args []string) (interface{}, error) {
Run: format.WrapCmd(func(_ []string) (interface{}, error) {
ctx := context.Background()
rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent()), client.WithRetryCount(viper.GetUint("retry")), client.WithLogger(log.CliLogger))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rekor-server/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
logType string
enablePprof bool
// these map to the operationId as defined in openapi.yaml file
operationIds = []string{
operationIDs = []string{
"searchIndex",
"getLogInfo",
"getPublicKey",
Expand Down Expand Up @@ -122,7 +122,7 @@ Memory and file-based signers should only be used for testing.`)
rootCmd.PersistentFlags().String("attestation_storage_bucket", "", "url for attestation storage bucket")
rootCmd.PersistentFlags().Int("max_attestation_size", 100*1024, "max size for attestation storage, in bytes")

rootCmd.PersistentFlags().StringSlice("enabled_api_endpoints", operationIds, "list of API endpoints to enable using operationId from openapi.yaml")
rootCmd.PersistentFlags().StringSlice("enabled_api_endpoints", operationIDs, "list of API endpoints to enable using operationId from openapi.yaml")

rootCmd.PersistentFlags().Uint64("max_request_body_size", 0, "maximum size for HTTP request body, in bytes; set to 0 for unlimited")
rootCmd.PersistentFlags().Uint64("max_jar_metadata_size", 1048576, "maximum permitted size for jar META-INF/ files, in bytes; set to 0 for unlimited")
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-server/app/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var serveCmd = &cobra.Command{
Use: "serve",
Short: "start http server with configured api",
Long: `Starts a http server and serves the configured api`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// Setup the logger to dev/prod
log.ConfigureLogger(viper.GetString("log_type"), viper.GetString("trace-string-prefix"))

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func NewRedisClient() *redis.Client {
// #nosec G402
if viper.GetBool("redis_server.enable-tls") {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: viper.GetBool("redis_server.insecure-skip-verify"),
InsecureSkipVerify: viper.GetBool("redis_server.insecure-skip-verify"), //nolint: gosec
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ const (
func signEntry(ctx context.Context, signer signature.Signer, entry models.LogEntryAnon) ([]byte, error) {
payload, err := entry.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("marshalling error: %v", err)
return nil, fmt.Errorf("marshalling error: %w", err)
}
canonicalized, err := jsoncanonicalizer.Transform(payload)
if err != nil {
return nil, fmt.Errorf("canonicalizing error: %v", err)
return nil, fmt.Errorf("canonicalizing error: %w", err)
}
signature, err := signer.SignMessage(bytes.NewReader(canonicalized), options.WithContext(ctx))
if err != nil {
return nil, fmt.Errorf("signing error: %v", err)
return nil, fmt.Errorf("signing error: %w", err)
}
return signature, nil
}
Expand Down Expand Up @@ -287,12 +287,12 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl

signature, err := signEntry(ctx, api.signer, logEntryAnon)
if err != nil {
return nil, handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("signing entry error: %v", err), signingError)
return nil, handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("signing entry error: %w", err), signingError)
}

root := &ttypes.LogRootV1{}
if err := root.UnmarshalBinary(resp.GetLeafAndProofResult.SignedLogRoot.LogRoot); err != nil {
return nil, handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("error unmarshalling log root: %v", err), sthGenerateError)
return nil, handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("error unmarshalling log root: %w", err), sthGenerateError)
}
hashes := []string{}
for _, hash := range resp.GetLeafAndProofResult.Proof.Hashes {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/rekor_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestGetRekorClientWithRetryCount(t *testing.T) {
expectedCount := 2
actualCount := 0
testServer := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
func(w http.ResponseWriter, _ *http.Request) {
actualCount++
file := []byte{}

Expand All @@ -111,7 +111,7 @@ func TestGetRekorClientWithRetryCount(t *testing.T) {

func TestRekorLeakedGoroutine_SearchByHash(t *testing.T) {
testServer := httptest.NewUnstartedServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
func(w http.ResponseWriter, _ *http.Request) {
file := []byte("ok")

w.WriteHeader(http.StatusOK)
Expand Down
5 changes: 3 additions & 2 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package events

import (
"encoding/json"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -88,10 +89,10 @@ func (e Event) Message() protoreflect.ProtoMessage {
// - time.Time
func (t *EventType) New(id string, msg protoreflect.ProtoMessage, attributes map[string]any) (*Event, error) {
if id == "" {
return nil, fmt.Errorf("id must be set")
return nil, errors.New("id must be set")
}
if msg == nil {
return nil, fmt.Errorf("msg must be set")
return nil, errors.New("msg must be set")
}
ty := msg.ProtoReflect().Descriptor().FullName()
if tty := t.Descriptor().FullName(); ty != tty {
Expand Down
11 changes: 6 additions & 5 deletions pkg/fuzz/alpine_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -306,20 +307,20 @@ func CreateAlpineProps(ff *fuzz.ConsumeFuzzer) (types.ArtifactProperties, func()
return *props, cleanupArtifactFile, err
}
if props.ArtifactPath == nil && props.ArtifactBytes == nil {
return *props, cleanupArtifactFile, fmt.Errorf("ArtifactPath and ArtifactBytes cannot both be nil")
return *props, cleanupArtifactFile, errors.New("ArtifactPath and ArtifactBytes cannot both be nil")
}

err = setAdditionalAuthenticatedData(ff, props)
if err != nil {
return *props, cleanupArtifactFile, fmt.Errorf("Failed setting AdditionalAuthenticatedData")
return *props, cleanupArtifactFile, errors.New("Failed setting AdditionalAuthenticatedData")
}

cleanupSignatureFile, err := setSignatureFields(ff, props)
if err != nil {
return *props, func() {
cleanupArtifactFile()
cleanupSignatureFile()
}, fmt.Errorf("failed setting signature fields: %v", err)
}, fmt.Errorf("failed setting signature fields: %w", err)
}

cleanupPublicKeyFile, err := setPublicKeyFields(ff, props)
Expand All @@ -328,7 +329,7 @@ func CreateAlpineProps(ff *fuzz.ConsumeFuzzer) (types.ArtifactProperties, func()
cleanupArtifactFile()
cleanupSignatureFile()
cleanupPublicKeyFile()
}, fmt.Errorf("failed setting public key fields: %v", err)
}, fmt.Errorf("failed setting public key fields: %w", err)
}

err = setPKIFormat(ff, props)
Expand All @@ -337,7 +338,7 @@ func CreateAlpineProps(ff *fuzz.ConsumeFuzzer) (types.ArtifactProperties, func()
cleanupArtifactFile()
cleanupSignatureFile()
cleanupPublicKeyFile()
}, fmt.Errorf("failed setting PKI Format: %v", err)
}, fmt.Errorf("failed setting PKI Format: %w", err)
}

return *props, func() {
Expand Down
17 changes: 9 additions & 8 deletions pkg/fuzz/fuzz_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package fuzz
import (
"archive/zip"
"bytes"
"errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -182,7 +183,7 @@ func createDefaultArtifactFiles(ff *fuzz.ConsumeFuzzer) ([]*fuzz.TarFile, error)
}
for _, file := range files {
if len(file.Body) == 0 {
return files, fmt.Errorf("Created an empty file")
return files, errors.New("Created an empty file")
}
}
return files, nil
Expand All @@ -206,42 +207,42 @@ func CreateProps(ff *fuzz.ConsumeFuzzer, fuzzType string) (types.ArtifactPropert

err = setAdditionalAuthenticatedData(ff, props)
if err != nil {
return *props, cleanups, fmt.Errorf("Failed setting AdditionalAuthenticatedData")
return *props, cleanups, errors.New("Failed setting AdditionalAuthenticatedData")
}

cleanupSignatureFile, err := setSignatureFields(ff, props)
if err != nil {
return *props, cleanups, fmt.Errorf("failed setting signature fields: %v", err)
return *props, cleanups, fmt.Errorf("failed setting signature fields: %w", err)
}
cleanups = append(cleanups, cleanupSignatureFile)

cleanupPublicKeyFile, err := setPublicKeyFields(ff, props)
if err != nil {
return *props, cleanups, fmt.Errorf("failed setting public key fields: %v", err)
return *props, cleanups, fmt.Errorf("failed setting public key fields: %w", err)
}
cleanups = append(cleanups, cleanupPublicKeyFile)

err = setPKIFormat(ff, props)
if err != nil {
return *props, cleanups, fmt.Errorf("failed setting PKI Format: %v", err)
return *props, cleanups, fmt.Errorf("failed setting PKI Format: %w", err)
}

artifactBytes, err := tarFilesToBytes(artifactFiles, fuzzType)
if err != nil {
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %v", err)
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %w", err)
}

setArtifactBytes, err := ff.GetBool()
if err != nil {
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %v", err)
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %w", err)
}
if setArtifactBytes {
props.ArtifactBytes = artifactBytes
} else {
artifactFile, err := createAbsFile(ff, "ArtifactFile", artifactBytes)
cleanups = append(cleanups, func() { os.Remove("ArtifactFile") })
if err != nil {
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %v", err)
return *props, cleanups, fmt.Errorf("failed converting artifact bytes: %w", err)
}
props.ArtifactPath = artifactFile
}
Expand Down
Loading

0 comments on commit 2da64d6

Please sign in to comment.