Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 improve debug output of scan job #188

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec {
}

func (p *Provisioner) executeCnspec(ui packer.Ui, comm packer.Communicator) error {

assetConfig := &inventory.Config{
Type: "unkown",
Options: map[string]string{},
Expand Down Expand Up @@ -437,8 +436,12 @@ func (p *Provisioner) executeCnspec(ui packer.Ui, comm packer.Communicator) erro
debugLogBuffer := &bytes.Buffer{}
logger.SetWriter(debugLogBuffer)
if p.config.Debug {
data, _ := json.Marshal(scanJob)
ui.Message(fmt.Sprintf("cnspec job configuration: %v", string(data)))
raw, err := json.MarshalIndent(scanJob, "", " ")
if err != nil {
ui.Error("failed to dump JSON:" + err.Error())
}

ui.Message(fmt.Sprintf("cnspec job configuration: %v", string(raw)))

// configure stderr logger
logger.Set("debug")
Expand All @@ -447,6 +450,14 @@ func (p *Provisioner) executeCnspec(ui packer.Ui, comm packer.Communicator) erro
defer func() {
ui.Message(debugLogBuffer.String())
}()

DumpLocal := "./mondoo-debug-"
name := p.config.AssetName

err = os.WriteFile(DumpLocal+name+".json", []byte(raw), 0o644)
if err != nil {
ui.Error("failed to dump JSON" + err.Error())
}
}

// base 64 config env setting has always precedence
Expand Down
Loading