Skip to content

Commit 2dfbad0

Browse files
nikpivkinsimar7
authored andcommitted
fix: fix metadata retrieval from iac types
Signed-off-by: Nikita Pivkin <[email protected]>
1 parent 954b982 commit 2dfbad0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/cloud/metadata.rego

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ import rego.v1
1010
obj_by_path(obj, path) := res if {
1111
occurrences := {obj_path: child_object |
1212
walk(obj, [obj_path, child_object])
13-
child_object.__defsec_metadata
13+
has_metadata(child_object)
1414
object.subset(path, obj_path)
1515
}
1616

1717
res := occurrences[max(object.keys(occurrences))]
1818
} else := obj
19+
20+
has_metadata(obj) if obj.__defsec_metadata
21+
22+
has_metadata(obj) if {
23+
obj.fskey
24+
has_key(obj, "value")
25+
}
26+
27+
has_key(x, k) if _ = x[k]

lib/cloud/metadata_test.rego

+7
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@ test_obj_by_path_skip_without_metadata if {
3131
metadata.obj_by_path(obj, ["foo", "baz"]) == obj
3232
}
3333

34+
test_obj_by_path_happy_iac_type if {
35+
bar := {"value": 1, "fskey": "somekey"}
36+
obj := with_meta({"foo": with_meta({"bar": bar})})
37+
38+
metadata.obj_by_path(obj, ["foo", "bar"]) == bar
39+
}
40+
3441
with_meta(obj) := object.union(obj, {"__defsec_metadata": {}})

0 commit comments

Comments
 (0)