Skip to content

Commit

Permalink
🧹 Add bytes reporter to support the packer plugin
Browse files Browse the repository at this point in the history
This adds a reporter which allows to access the rendered report as bytes.Buffer.
This is needed, so we can output it inside the packer plugin.

For reference: mondoohq/packer-plugin-cnspec#170

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Jan 10, 2024
1 parent 491537b commit 6a90f62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cli/reporter/cli_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ func NewReporter(format Format, incognito bool) *Reporter {
}
}

// This allows the packer-plugin-cnspec to set the output writer directly
// The plugin needs this to work the the packer output
func (r *Reporter) WithOutput(out io.Writer) *Reporter {
r.out = out
return r
}

func (r *Reporter) WriteReport(ctx context.Context, data *policy.ReportCollection) error {
switch r.Format {
case Compact:
Expand Down
3 changes: 0 additions & 3 deletions cli/reporter/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ func (h *localFileHandler) WriteReport(ctx context.Context, report *policy.Repor
}
defer f.Close() //nolint: errcheck
reporter := NewReporter(h.format, false)
if err != nil {
return err
}
reporter.out = f
err = reporter.WriteReport(ctx, report)
if err != nil {
Expand Down

0 comments on commit 6a90f62

Please sign in to comment.