Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.

Commit 516a1a0

Browse files
committed
extend rego parsing support
1 parent 0706750 commit 516a1a0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sphinxrego/opa.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,19 @@ def _recu_rego_json_to_obj(_r: dict) -> Union[dict, list, str, bool, int, None]:
7777
return _r["value"]
7878
if _r["type"] == "null":
7979
return None
80+
if _r["type"] == "var":
81+
return _r["value"] # variables are stores as strings
82+
if _r["type"] == "ref" and isinstance(_r["value"], list) and len(_r["value"]) >= 1:
83+
return ".".join([_recu_rego_json_to_obj(_r_ref_part) for _r_ref_part in _r["value"]])
84+
if _r["type"] == "call" and isinstance(_r["value"], list) and len(_r["value"]) >= 1:
85+
func_name = _recu_rego_json_to_obj(_r["value"][0])
86+
func_args = ",".join([_recu_rego_json_to_obj(_r_arg) for _r_arg in _r["value"][1:]])
87+
return f"{func_name}({func_args})"
8088
if _r["type"] == "object":
8189
return {_recu_rego_json_to_obj(v1): _recu_rego_json_to_obj(v2) for v1, v2 in _r["value"]}
8290
if _r["type"] == "array":
8391
return [_recu_rego_json_to_obj(v) for v in _r["value"]]
84-
raise ValueError(f"Unable to parse object {_r}")
92+
raise ValueError(f"Unable to parse type: {_r['type']}, object {_r}")
8593

8694
# if `r` is a dict then `_recu_rego_json_to_obj(r)` is also a dict
8795
new = _recu_rego_json_to_obj(r)

0 commit comments

Comments
 (0)