Skip to content

Commit

Permalink
🐛 fix bundle fmt command to properly convert v7 to v8 (#477)
Browse files Browse the repository at this point in the history
`scoring_system` completely disappeared when running `cnspec bundle
fmt`. This PR fixes the problem. I confirmed this by taking a v7 policy
and running `cnspec bundle fmt` for it with latest `main` and with this
branch. The only difference between the output of the 2 is the added
`scoring_system`.

---------

Signed-off-by: Ivan Milchev <ivan@mondoo.com>
  • Loading branch information
imilchev authored Mar 27, 2023
1 parent 7466bce commit 2b6d18f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestParser_DeprecatedV7(t *testing.T) {
Value: &ImpactValue{
Value: 30,
},
FileContext: FileContext{26, 13},
FileContext: FileContext{27, 13},
}, baseline.Queries[0].Impact)
}

Expand Down
5 changes: 4 additions & 1 deletion internal/bundle/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bundle

import (
"bytes"
"encoding/json"
"os"

"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -69,7 +70,9 @@ func DeprecatedV7_ToV8(data []byte) ([]byte, error) {
// this step will unfortunately not produce well-formatted YAML at all
// because the proto structures don't have the yaml tags (only the
// yac-it structures do) ...
interim, err := Format(v8)
// for the same reason we convert between the 2 types using JSON since both
// structs contain the JSON tags.
interim, err := json.Marshal(v8)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/bundle/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ policies:
scoring_queries:
query1:
version: "1.0.0"
scoring_system: 2
queries:
- uid: query1
docs:
Expand Down Expand Up @@ -57,6 +58,7 @@ queries:
- filters: platform.family.contains(_ == 'unix')
checks:
- uid: query1
scoring_system: 2
queries:
- uid: query1
title: Ensure Secure Boot is enabled
Expand Down

0 comments on commit 2b6d18f

Please sign in to comment.