python-3.xcasbin

Custom function in casbin matcher in pycasbin for restful apis


Hi I want to check for roles single or multiple in the matcher for my restful apis endpoint, I am getting roles as list of strings, I want to enfore casbin permission for the endpoints. How do I create custom function in python, I am not getting any detail for python here (https://casbin.org/docs/en/function) I am using pycasbin.

my auth_policy:

p, custom_role, endpoint, GET

in my authz_model.conf, I want to add my custom_func(p.role,r.role) instead of checking p.role==r.role


Solution

  • Please use add_function(), see: https://github.com/casbin/pycasbin/issues/215

    Here's an example: https://github.com/casbin/pycasbin/pull/217