|
| 1 | +/* |
| 2 | +* Copyright 2021 The casbin Authors. All Rights Reserved. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#include <pybind11/pybind11.h> |
| 18 | +#include <pybind11/stl.h> |
| 19 | +#include <casbin/casbin.h> |
| 20 | + |
| 21 | +namespace py = pybind11; |
| 22 | + |
| 23 | +void bindPyCachedEnforcer(py::module &m) { |
| 24 | + py::class_<casbin::CachedEnforcer, casbin::Enforcer>(m, "CachedEnforcer") |
| 25 | + .def(py::init<>(), "Enforcer is the default constructor.") |
| 26 | + .def(py::init<const std::string &, const std::string &>(), R"doc( |
| 27 | + Enforcer initializes an enforcer with a model file and a policy file. |
| 28 | + @param model_path the path of the model file. |
| 29 | + @param policy_file the path of the policy file. |
| 30 | + )doc") |
| 31 | + .def(py::init<const std::string &, std::shared_ptr<casbin::Adapter>>(), R"doc( |
| 32 | + Enforcer initializes an enforcer with a database adapter. |
| 33 | + @param model_path the path of the model file. |
| 34 | + @param adapter the adapter. |
| 35 | + )doc") |
| 36 | + .def(py::init<std::shared_ptr<casbin::Model>, std::shared_ptr<casbin::Adapter>>(), R"doc( |
| 37 | + Enforcer initializes an enforcer with a model and a database adapter. |
| 38 | + @param m the model. |
| 39 | + @param adapter the adapter. |
| 40 | + )doc") |
| 41 | + .def(py::init<std::shared_ptr<casbin::Model>>(), R"doc( |
| 42 | + Enforcer initializes an enforcer with a model. |
| 43 | + @param m the model. |
| 44 | + )doc") |
| 45 | + .def(py::init<const std::string &>(), R"doc( |
| 46 | + Enforcer initializes an enforcer with a model file. |
| 47 | + @param model_path the path of the model file. |
| 48 | + )doc") |
| 49 | + .def(py::init<const std::string &, const std::string &, bool>(), R"doc( |
| 50 | + Enforcer initializes an enforcer with a model file, a policy file and an enable log flag. |
| 51 | + @param model_path the path of the model file. |
| 52 | + @param policy_file the path of the policy file. |
| 53 | + @param enable_log whether to enable Casbin's log. |
| 54 | + )doc") |
| 55 | + |
| 56 | + // .def("Enforce", py::overload_cast<casbin::Scope>(&casbin::CachedEnforcer::Enforce), R"doc( |
| 57 | + // Enforce with a vector param,decides whether a "subject" can access a |
| 58 | + // "object" with the operation "action", input parameters are usually: (sub, |
| 59 | + // obj, act). |
| 60 | + // )doc") |
| 61 | + .def("Enforce", py::overload_cast<const casbin::DataList &>(&casbin::CachedEnforcer::Enforce), R"doc( |
| 62 | + Enforce with a map param,decides whether a "subject" can access a "object" |
| 63 | + with the operation "action", input parameters are usually: (sub, obj, act). |
| 64 | + )doc") |
| 65 | + .def("Enforce", py::overload_cast<const casbin::DataMap &>(&casbin::CachedEnforcer::Enforce), R"doc( |
| 66 | + Enforce with a map param,decides whether a "subject" can access a "object" |
| 67 | + with the operation "action", input parameters are usually: (sub, obj, act). |
| 68 | + )doc") |
| 69 | + // .def("EnforceWithMatcher", py::overload_cast<const std::string &, casbin::Scope>(&casbin::CachedEnforcer::EnforceWithMatcher), R"doc( |
| 70 | + // EnforceWithMatcher use a custom matcher to decides whether a "subject" can |
| 71 | + // access a "object" with the operation "action", input parameters are |
| 72 | + // usually: (matcher, sub, obj, act), use model matcher by default when |
| 73 | + // matcher is "". |
| 74 | + // )doc") |
| 75 | + .def("EnforceWithMatcher", py::overload_cast<const std::string &, const casbin::DataList &>(&casbin::CachedEnforcer::EnforceWithMatcher), R"doc( |
| 76 | + EnforceWithMatcher use a custom matcher to decides whether a "subject" can |
| 77 | + access a "object" with the operation "action", input parameters are |
| 78 | + usually: (matcher, sub, obj, act), use model matcher by default when |
| 79 | + matcher is "". |
| 80 | + )doc") |
| 81 | + .def("EnforceWithMatcher", py::overload_cast<const std::string &, const casbin::DataMap &>(&casbin::CachedEnforcer::EnforceWithMatcher), R"doc( |
| 82 | + EnforceWithMatcher use a custom matcher to decides whether a "subject" can |
| 83 | + access a "object" with the operation "action", input parameters are |
| 84 | + usually: (matcher, sub, obj, act), use model matcher by default when |
| 85 | + matcher is "". |
| 86 | + )doc"); |
| 87 | +} |
0 commit comments