0

Iam trying to unMarshal AST json to ast.Module structure of OPA.

policy.rego:

package example.authz import rego.v1 allow if { some i input.users[i].role == "admin" } 

use command opa parse --v1-compatible --format json policy.rego generated ast:

{ "package": { "path": [ { "type": "var", "value": "data" }, { "type": "string", "value": "example" }, { "type": "string", "value": "authz" } ] }, "imports": [ { "path": { "type": "ref", "value": [ { "type": "var", "value": "rego" }, { "type": "string", "value": "v1" } ] } } ], "rules": [ { "body": [ { "index": 0, "terms": { "symbols": [ { "type": "var", "value": "i" } ] } }, { "index": 1, "terms": [ { "type": "ref", "value": [ { "type": "var", "value": "equal" } ] }, { "type": "ref", "value": [ { "type": "var", "value": "input" }, { "type": "string", "value": "users" }, { "type": "var", "value": "i" }, { "type": "string", "value": "role" } ] }, { "type": "string", "value": "admin" } ] } ], "head": { "name": "allow", "value": { "type": "boolean", "value": true }, "ref": [ { "type": "var", "value": "allow" } ] } } ] } 

go code converting json bytes into ast.Module

 var module ast.Module module.SetRegoVersion(ast.RegoV1) if err = module.UnmarshalJSON(b); err != nil { panic(err) } 

I am getting error panic: ast: unable to unmarshal term. The problem is with keyword "some". if there is "some" keyword in original rego it is not Unmarshalling to ast.Module

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.