Skip to content

Commit

Permalink
lint and test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Callaway <[email protected]>
  • Loading branch information
bobcallaway committed Oct 31, 2024
1 parent 2288676 commit ae72b9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/client/rekor_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func GetRekorClient(rekorServerURL string, opts ...Option) (*client.Rekor, error
rt := httptransport.NewWithClient(url.Host, url.Path, []string{url.Scheme}, httpClient)
rt.Consumers["application/json"] = runtime.JSONConsumer()
rt.Consumers["application/x-pem-file"] = runtime.TextConsumer()
rt.Consumers[tle.TLEMediaType] = &tle.TLEConsumer{}
rt.Consumers[tle.TLEMediaType] = &tle.Consumer{}
rt.Producers["application/json"] = runtime.JSONProducer()
rt.DefaultMediaType = "application/json"

Expand Down
2 changes: 1 addition & 1 deletion pkg/generated/restapi/configure_rekor_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func configureAPI(api *operations.RekorServerAPI) http.Handler {
api.JSONProducer = runtime.JSONProducer()

api.ApplicationXPemFileProducer = runtime.TextProducer()
api.ApplicationXSigstoreTleProducer = tle.TLEProducer{}
api.ApplicationXSigstoreTleProducer = &tle.Producer{}

// disable all endpoints to start
api.IndexSearchIndexHandler = index.SearchIndexHandlerFunc(pkgapi.SearchIndexNotImplementedHandler)
Expand Down
30 changes: 15 additions & 15 deletions pkg/tle/tle.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func MarshalTLEToJSON(tle *rekor_pb.TransparencyLogEntry) ([]byte, error) {
return protojson.Marshal(tle)
}

func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) *models.LogEntry {
func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) models.LogEntry {
if tle == nil {
return nil
}

entryUUID := hex.EncodeToString(rfc6962.DefaultHasher.HashLeaf(tle.CanonicalizedBody))
inclusionProofHashes := []string{}
for _, hash := range tle.InclusionProof.Hashes {
inclusionProofHashes = append(inclusionProofHashes, hex.EncodeToString(hash))
inclusionProofHashes = append(inclusionProofHashes, base64.StdEncoding.EncodeToString(hash))
}
return &models.LogEntry{
return models.LogEntry{
entryUUID: models.LogEntryAnon{
Body: tle.CanonicalizedBody,
IntegratedTime: swag.Int64(tle.IntegratedTime),
Expand All @@ -142,9 +142,9 @@ func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) *models.LogEntry {
}
}

type TLEProducer struct{}
type Producer struct{}

func (t TLEProducer) Produce(w io.Writer, input interface{}) error {
func (t Producer) Produce(w io.Writer, input interface{}) error {
switch i := input.(type) {
case models.LogEntry:
var entry models.LogEntryAnon
Expand Down Expand Up @@ -189,9 +189,9 @@ func (t TLEProducer) Produce(w io.Writer, input interface{}) error {
return nil
}

type TLEConsumer struct{}
type Consumer struct{}

func (t TLEConsumer) Consume(r io.Reader, output interface{}) error {
func (t Consumer) Consume(r io.Reader, output interface{}) error {
tleBytes, err := io.ReadAll(r)
if err != nil {
return err
Expand All @@ -215,11 +215,11 @@ func (t TLEConsumer) Consume(r io.Reader, output interface{}) error {
if err := protojson.Unmarshal(element, msg); err != nil {
return fmt.Errorf("parsing element: %w", err)
}
if result, ok := output.([]models.LogEntry); ok {
if result, ok := output.(*[]models.LogEntry); ok {
logEntry := GenerateLogEntry(msg)
result = append(result, *logEntry)
} else if result, ok := output.([]*rekor_pb.TransparencyLogEntry); ok {
result = append(result, msg)
*result = append(*result, logEntry)
} else if result, ok := output.(*[]*rekor_pb.TransparencyLogEntry); ok {
*result = append(*result, msg)
} else {
return errors.New("unsupported conversion")
}
Expand All @@ -231,11 +231,11 @@ func (t TLEConsumer) Consume(r io.Reader, output interface{}) error {
if err := protojson.Unmarshal(tleBytes, tle); err != nil {
return fmt.Errorf("parsing element: %w", err)
}
if _, ok := output.(*rekor_pb.TransparencyLogEntry); ok {
output = tle
if result, ok := output.(**rekor_pb.TransparencyLogEntry); ok {
*result = tle
return nil
} else if _, ok := output.(*models.LogEntry); ok {
output = GenerateLogEntry(tle)
} else if result, ok := output.(*models.LogEntry); ok {
*result = GenerateLogEntry(tle)
return nil
} else {
return errors.New("unsupported conversion")
Expand Down

0 comments on commit ae72b9d

Please sign in to comment.