|
| 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 bindABACData(py::module& m) { |
| 24 | + py::class_<casbin::ABACData>(m, "ABACData") |
| 25 | + .def(py::init<const casbin::AttributeMap &>(), R"doc( |
| 26 | + @brief Construct a new casbin::ABACData object |
| 27 | +
|
| 28 | + @param attribs Should be of the format: { |
| 29 | + { "attrib_name1", value1 }, |
| 30 | + { "attring_name2", value2 }, |
| 31 | + ... |
| 32 | + } |
| 33 | +
|
| 34 | + Key's type is std::string and value's type can be one of std::string, int32_t, double, and float only |
| 35 | + )doc") |
| 36 | + .def("AddAttribute", &casbin::ABACData::AddAttribute, R"doc( |
| 37 | + @brief Add attribute to the corresponding ABAC entity |
| 38 | + @param key Name of the attribute |
| 39 | + @param value Value of the attribute |
| 40 | + @return true when attribute is added successfully, false otherwise |
| 41 | + )doc") |
| 42 | + .def("AddAttributes", &casbin::ABACData::AddAttributes, R"doc( |
| 43 | + @brief Add attributes to the corresponding ABAC entity |
| 44 | +
|
| 45 | + @param attribs Should be of the format: { |
| 46 | + { "attrib_name1", value1 }, |
| 47 | + { "attring_name2", value2 }, |
| 48 | + ... |
| 49 | + } |
| 50 | +
|
| 51 | + Key's type is std::string and value's type can be one of std::string, int32_t, and float only |
| 52 | + @return true if attributes are added successfully, false otherwise |
| 53 | +
|
| 54 | + )doc") |
| 55 | + .def("DeleteAttribute", &casbin::ABACData::DeleteAttribute, R"doc( |
| 56 | + @brief Delete attribute of the corresponding ABAC entity |
| 57 | + @param key Name of the attribute to be deleted |
| 58 | + @return true when attribute is deleted successfully, false otherwise |
| 59 | + )doc") |
| 60 | + .def("UpdateAttribute", &casbin::ABACData::UpdateAttribute, R"doc( |
| 61 | + @brief Update attribute of the corresponding ABAC entity |
| 62 | + @param key Name of the attribute to be updated |
| 63 | + @param value Value which would replace the current value of the attribute corresponding |
| 64 | + to the given key |
| 65 | + @return true |
| 66 | + @return false |
| 67 | + )doc"); |
| 68 | + // .def("GetAttributes", &casbin::ABACData::GetAttributes, R"doc( |
| 69 | + // @brief Get the Attributes of the corresponding ABAC entity |
| 70 | + // @return const reference to the hashmap containing attributes in key-value pairs |
| 71 | + // )doc"); |
| 72 | + |
| 73 | + m.def("GetDataObject", &casbin::GetDataObject, R"doc( |
| 74 | + @brief Get casbin::ABACData object |
| 75 | + @param attribs Should be of the format: { |
| 76 | + { "attrib_name1", value1 }, |
| 77 | + { "attrib_name2", value2 }, |
| 78 | + ... |
| 79 | + } |
| 80 | + Key's type is std::string and value's type can be one of std::string, int32_t, double, and float only |
| 81 | + @return Pointer to casbin::ABACData entity |
| 82 | + )doc"); |
| 83 | +} |
0 commit comments