|
| 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 | +#include "py_casbin.h" |
| 22 | + |
| 23 | +void bindPyModel(py::module &m) { |
| 24 | + py::class_<casbin::Model>(m, "Model") |
| 25 | + .def(py::init<>()) |
| 26 | + .def(py::init<const std::string &>()) |
| 27 | + |
| 28 | + .def("HasSection", &casbin::Model::HasSection) |
| 29 | + .def("AddDef", &casbin::Model::AddDef, "AddDef adds an assertion to the model.") |
| 30 | + .def("LoadModel", &casbin::Model::LoadModel, "LoadModel loads the model from model CONF file.") |
| 31 | + .def("LoadModelFromText", &casbin::Model::LoadModelFromText, "LoadModelFromText loads the model from the text.") |
| 32 | + .def("LoadModelFromConfig", &casbin::Model::LoadModelFromConfig) |
| 33 | + .def("PrintModel", &casbin::Model::PrintModel, "PrintModel prints the model to the log.") |
| 34 | + |
| 35 | + .def("BuildIncrementalRoleLinks", &casbin::Model::BuildIncrementalRoleLinks) |
| 36 | + .def("BuildRoleLinks", &casbin::Model::BuildRoleLinks, "BuildRoleLinks initializes the roles in RBAC.") |
| 37 | + .def("PrintPolicy", &casbin::Model::PrintPolicy, "PrintPolicy prints the policy to log.") |
| 38 | + .def("ClearPolicy", &casbin::Model::ClearPolicy, "ClearPolicy clears all current policy.") |
| 39 | + .def("GetPolicy", &casbin::Model::GetPolicy, "GetPolicy gets all rules in a policy.") |
| 40 | + .def("GetFilteredPolicy", &casbin::Model::GetFilteredPolicy, "GetFilteredPolicy gets rules based on field filters from a policy.") |
| 41 | + .def("HasPolicy", &casbin::Model::HasPolicy, "HasPolicy determines whether a model has the specified policy rule.") |
| 42 | + .def("AddPolicy", &casbin::Model::AddPolicy, "AddPolicy adds a policy rule to the model.") |
| 43 | + .def("AddPolicies", &casbin::Model::AddPolicies, "AddPolicies adds policy rules to the model.") |
| 44 | + .def("UpdatePolicy", &casbin::Model::UpdatePolicy, "UpdatePolicy updates a policy rule from the model.") |
| 45 | + .def("UpdatePolicies", &casbin::Model::UpdatePolicies, "UpdatePolicies updates a set of policy rules from the model.") |
| 46 | + .def("RemovePolicy", &casbin::Model::RemovePolicy, "RemovePolicy removes a policy rule from the model.") |
| 47 | + .def("RemovePolicies", &casbin::Model::RemovePolicies, "RemovePolicies removes policy rules from the model.") |
| 48 | + .def("RemoveFilteredPolicy", &casbin::Model::RemoveFilteredPolicy, "RemoveFilteredPolicy removes policy rules based on field filters from the model.") |
| 49 | + .def("GetValuesForFieldInPolicy", &casbin::Model::GetValuesForFieldInPolicy, "GetValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.") |
| 50 | + .def("GetValuesForFieldInPolicyAllTypes", &casbin::Model::GetValuesForFieldInPolicyAllTypes, "GetValuesForFieldInPolicyAllTypes gets all values for a field for all rules in a policy of all p_types, duplicated values are removed.") |
| 51 | + |
| 52 | + .def_static("NewModel", &casbin::Model::NewModel, "NewModel creates an empty model.") |
| 53 | + .def_static("NewModelFromFile", &casbin::Model::NewModelFromFile, "NewModelFromFile creates a model from a .CONF file.") |
| 54 | + .def_static("NewModelFromString", &casbin::Model::NewModelFromString, "NewModel creates a model from a std::string which contains model text."); |
| 55 | +} |
0 commit comments