OPA Rego功能声明评估顺序

时间:2020-02-10 09:44:41

标签: open-policy-agent rego

package play


exists(obj, a) {
   obj[a]
}


hello {
     exists(input, "department")
     contains(input["location"], "London")
}

world {        
    contains(input["location"], "London")
    exists(input, "department")    
}

输入= { “部门”:“英语”, “ location”:“伦敦”}

以上代码仅匹配你好。为什么即使条件相同但 world 仍然不匹配,但是顺序相反?

1 个答案:

答案 0 :(得分:2)

语句的顺序无关紧要。您实际上已经找到了a bug

如果您稍稍更改示例,以使exists不是第一个参数而调用input,而是像exists(input.user, "department")这样的名称,然后更新输入文档以反映该情况:< / p>

{"user": {"department": "Eng", "location": "London"}}

您将观察到正确的行为(例如world { contains(input.user["location"], "London"); exists(input.user, "department") })。