0

can we load the policies directly form string in casbin similar to model

I want similar for policies instead of loading from csv file

text :=
`
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
`
m, _ := model.NewModelFromString(text)
Akshay
  • 107
  • 2
  • 11

1 Answers1

-1

Yes, it is possible you can load the String into the model( not policy). The above example that you have given is for model.

from casbin.core_enforcer import CoreEnforcer

text =
`
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
`

model = CoreEnforcer.new_model("", txt)
enforcer = casbin.Enforcer(model, adapter)