Skip to content

Commit

Permalink
feat(misconf): export unresolvable field of IaC types to Rego (#7765)
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <[email protected]>
  • Loading branch information
nikpivkin authored Oct 21, 2024
1 parent 010b213 commit 9514148
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/iac/rego/convert/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Test_SliceTypesConversion(t *testing.T) {
"endline": 123,
"sourceprefix": "",
"managed": true,
"unresolvable": false,
"explicit": false,
"fskey": "",
"resource": "",
Expand All @@ -49,6 +50,7 @@ func Test_SliceTypesConversion(t *testing.T) {
"endline": 123,
"sourceprefix": "",
"managed": true,
"unresolvable": false,
"explicit": false,
"fskey": "",
"resource": "",
Expand Down
21 changes: 21 additions & 0 deletions pkg/iac/rego/schemas/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -7884,6 +7884,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "boolean"
}
Expand Down Expand Up @@ -7916,6 +7919,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "string"
}
Expand Down Expand Up @@ -7948,6 +7954,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "integer"
}
Expand Down Expand Up @@ -7980,6 +7989,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "object"
}
Expand Down Expand Up @@ -8011,6 +8023,9 @@
},
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -8041,6 +8056,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "string"
}
Expand Down Expand Up @@ -8073,6 +8091,9 @@
"startline": {
"type": "integer"
},
"unresolvable": {
"type": "boolean"
},
"value": {
"type": "string"
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/iac/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func Test_RegoConversion(t *testing.T) {
"startline": 2,
"endline": 4,
"managed": true,
"unresolvable": false,
"explicit": false,
"fskey": "",
},
Expand All @@ -55,6 +56,7 @@ func Test_RegoConversion(t *testing.T) {
"endline": 3,
"value": "my-bucket",
"managed": true,
"unresolvable": false,
"explicit": false,
"fskey": "",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/iac/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (m *Metadata) ToRego() any {
"sourceprefix": m.Range().GetSourcePrefix(),
"managed": m.isManaged,
"explicit": m.isExplicit,
"unresolvable": m.isUnresolvable,
"fskey": CreateFSKey(m.Range().GetFS()),
"resource": m.Reference(),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/iac/types/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (

func Test_MetadataToRego(t *testing.T) {
m1 := NewTestMetadata()
m1.isUnresolvable = true
expected := map[string]any{
"endline": 123,
"explicit": false,
"filepath": "test.test",
"fskey": "",
"managed": true,
"unresolvable": true,
"resource": "",
"sourceprefix": "",
"startline": 123,
Expand All @@ -27,6 +29,7 @@ func Test_MetadataToRego(t *testing.T) {
"filepath": "test.test",
"fskey": "",
"managed": true,
"unresolvable": false,
"resource": "",
"sourceprefix": "",
"startline": 123,
Expand Down

0 comments on commit 9514148

Please sign in to comment.