Skip to content

Commit

Permalink
⭐️ use proto reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Apr 3, 2024
1 parent d714dec commit 0e8ad61
Show file tree
Hide file tree
Showing 16 changed files with 666 additions and 322 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ prep/tools:

# 🌙 cnspec #

cnspec/generate: clean/proto cli/generate policy/generate
cnspec/generate: clean/proto cli/generate policy/generate reporter/generate

.PHONY: cli
cli/generate:
Expand All @@ -78,6 +78,9 @@ policy/generate:
go generate ./policy/scan
go generate ./internal/bundle/yacit

reporter/generate:
go generate ./cli/reporter

# 🏗 Binary #

.PHONY: cnspec/build
Expand Down
17 changes: 8 additions & 9 deletions apps/cnspec/cmd/vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
package cmd

import (
"bytes"
"strings"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -13,10 +14,8 @@ import (
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/upstream/mvd"
"go.mondoo.com/cnquery/v10/sbom"
"go.mondoo.com/cnquery/v10/shared"
"go.mondoo.com/cnspec/v10/cli/reporter"
"go.mondoo.com/cnspec/v10/policy"
"strings"
)

func init() {
Expand Down Expand Up @@ -62,17 +61,17 @@ var vulnCmdRun = func(cmd *cobra.Command, runtime *providers.Runtime, cliRes *pl

report, err := RunScan(conf)
if err != nil {
log.Fatal().Err(err).Msg("error happened during package analysis")
log.Fatal().Err(err).Msg("failed to run scan")
}

buf := bytes.Buffer{}
w := shared.IOWriter{Writer: &buf}
err = reporter.ReportCollectionToJSON(report, &w)
cnspecReport, err := reporter.ConvertToProto(report)
if err == nil {
logger.DebugDumpJSON("mondoo-sbom-report", buf.Bytes())
log.Debug().Msg("converted report to proto")
data, _ := cnspecReport.ToJSON()
logger.DebugDumpJSON("mondoo-sbom-report", data)
}

boms, err := sbom.NewBom(buf.Bytes())
boms, err := sbom.NewBom(cnspecReport.ToCnqueryReport())
if err != nil {
log.Fatal().Err(err).Msg("failed to parse sbom data")
}
Expand Down
4 changes: 2 additions & 2 deletions cli/reporter/cli_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func (r *Reporter) WriteReport(ctx context.Context, data *policy.ReportCollectio

case FormatJSON:
writer := shared.IOWriter{Writer: r.out}
return ReportCollectionToJSON(data, &writer)
return ConvertToJSON(data, &writer)
case FormatJUnit:
writer := shared.IOWriter{Writer: r.out}
return ReportCollectionToJunit(data, &writer)
return ConvertToJunit(data, &writer)
// case FormatCSV:
// res, err = data.ToCsv()
default:
Expand Down
Loading

0 comments on commit 0e8ad61

Please sign in to comment.