Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Jul 5, 2022
1 parent 69e6d64 commit a140b43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/mediocregopher/radix/v4 v4.1.0
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.2
github.com/rs/cors v1.8.2
github.com/sassoftware/relic v0.0.0-20210427151427-dfb082b79b74
Expand Down
14 changes: 8 additions & 6 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"net/http"
"net/url"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/go-openapi/swag"
"github.com/google/trillian"
ttypes "github.com/google/trillian/types"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/transparency-dev/merkle/rfc6962"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -313,7 +313,10 @@ func getEntryURL(locationURL url.URL, uuid string) strfmt.URI {
func GetLogEntryByUUIDHandler(params entries.GetLogEntryByUUIDParams) middleware.Responder {
logEntry, err := retrieveLogEntry(params.HTTPRequest.Context(), params.EntryUUID)
if err != nil {
return handleRekorAPIError(params, http.StatusNotFound, err, "ID %s not found in any known trees", params.EntryUUID)
if _, ok := (err).(types.ValidationError); ok {
return handleRekorAPIError(params, http.StatusBadRequest, err, "incorrectly formatted uuid %s", params.EntryUUID)
}
return handleRekorAPIError(params, http.StatusInternalServerError, err, "ID %s not found in any known trees", params.EntryUUID)
}
return entries.NewGetLogEntryByUUIDOK().WithPayload(logEntry)
}
Expand All @@ -333,8 +336,7 @@ func SearchLogQueryHandler(params entries.SearchLogQueryParams) middleware.Respo
if err != nil {
return handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf("could not get UUID from ID string %v", entryID))
}
logEntry, err := retrieveLogEntry(httpReqCtx, entryID)
if err == nil {
if logEntry, err := retrieveLogEntry(httpReqCtx, entryID); err == nil {
resultPayload = append(resultPayload, logEntry)
continue
}
Expand Down Expand Up @@ -455,7 +457,7 @@ var ErrNotFound = errors.New("grpc returned 0 leaves with success code")
func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, error) {
uuid, err := sharding.GetUUIDFromIDString(entryUUID)
if err != nil {
return models.LogEntry{}, errors.Wrap(err, "getting uuid from id string")
return models.LogEntry{}, sharding.ErrPlainUUID
}

// Get the tree ID and check that shard for the entry
Expand Down Expand Up @@ -484,7 +486,7 @@ func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, e
func retrieveUUIDFromTree(ctx context.Context, uuid string, tid int64) (models.LogEntry, error) {
hashValue, err := hex.DecodeString(uuid)
if err != nil {
return models.LogEntry{}, err
return models.LogEntry{}, types.ValidationError(err)
}

tc := NewTrillianClientFromTreeID(ctx, tid)
Expand Down

0 comments on commit a140b43

Please sign in to comment.