【问题标题】:OPA Rego function statement evaluation orderOPA Rego 函数语句评估顺序
【发布时间】:2020-02-10 09:44:41
【问题描述】:
package play


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


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

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

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

上面的代码只匹配 hello。为什么world即使条件相同也不匹配,但顺序相反?

【问题讨论】:

    标签: open-policy-agent rego


    【解决方案1】:

    语句的顺序无关紧要。你真的找到了a bug

    如果您稍微更改示例,以便不使用 input 作为第一个参数调用 exists,而是使用类似 exists(input.user, "department") 的名称,然后您更新输入文档以反映这一点:

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

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

    【讨论】:

    • 谢谢。任何其他可能的解决方案(除了在“用户”内嵌套对象)?什么时候会解决这个错误?我们可以更新和重新测试。
    • 这个错误应该会在接下来的几天内得到解决。请留意 0.17.2。
    猜你喜欢
    • 2021-12-07
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2019-02-06
    • 2013-04-10
    • 1970-01-01
    相关资源
    最近更新 更多