restful api 的 pycasbin 中的 casbin 匹配器中的自定义函数

Custom function in casbin matcher in pycasbin for restful apis

您好,我想在我的 restful api 端点的匹配器中检查单个或多个角色,我正在获取作为字符串列表的角色,我想为端点强制执行 casbin 权限。 如何在 python 中创建自定义函数,我没有获得 python here (https://casbin.org/docs/en/function 的任何详细信息) 我正在使用 pycasbin。

我的auth_policy:

p, custom_role, endpoint, GET

在我的 authz_model.conf 中,我想添加我的 custom_func(p.role,r.role) 而不是检查 p.role==r.role

请使用add_function(),见:https://github.com/casbin/pycasbin/issues/215

举个例子:https://github.com/casbin/pycasbin/pull/217