3 #include <zk/config.hpp>
5 #include <initializer_list>
11 #include "forwards.hpp"
35 return permission(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));
41 return permission(static_cast<unsigned int>(a) & static_cast<unsigned int>(b));
56 return (
self & perform) == perform;
59 std::ostream& operator<<(std::ostream&,
const permission&);
98 const std::string&
id()
const
116 std::size_t
hash(
const acl_rule& rule);
118 [[gnu::pure]]
bool operator==(
const acl_rule& lhs,
const acl_rule& rhs);
119 [[gnu::pure]]
bool operator!=(
const acl_rule& lhs,
const acl_rule& rhs);
120 [[gnu::pure]]
bool operator< (
const acl_rule& lhs,
const acl_rule& rhs);
121 [[gnu::pure]]
bool operator<=(
const acl_rule& lhs,
const acl_rule& rhs);
122 [[gnu::pure]]
bool operator> (
const acl_rule& lhs,
const acl_rule& rhs);
123 [[gnu::pure]]
bool operator>=(
const acl_rule& lhs,
const acl_rule& rhs);
125 std::ostream& operator<<(std::ostream&,
const acl_rule&);
127 std::string to_string(
const acl_rule&);
142 using iterator = std::vector<acl_rule>::iterator;
143 using const_iterator = std::vector<acl_rule>::const_iterator;
144 using size_type = std::size_t;
151 acl(std::vector<acl_rule> rules) noexcept;
154 acl(std::initializer_list<acl_rule> rules) :
161 size_type
size()
const {
return _impl.size(); }
173 const acl_rule&
at(size_type idx)
const {
return _impl.at(idx); }
174 acl_rule&
at(size_type idx) {
return _impl.at(idx); }
179 iterator
begin() {
return _impl.begin(); }
180 const_iterator
begin()
const {
return _impl.begin(); }
181 const_iterator cbegin()
const {
return _impl.begin(); }
186 iterator
end() {
return _impl.end(); }
187 const_iterator
end()
const {
return _impl.end(); }
188 const_iterator cend()
const {
return _impl.end(); }
192 void reserve(size_type capacity) { _impl.reserve(capacity); }
197 template <
typename... TArgs>
200 _impl.emplace_back(std::forward<TArgs>(args)...);
210 std::vector<acl_rule> _impl;
213 [[gnu::pure]]
bool operator==(
const acl& lhs,
const acl& rhs);
214 [[gnu::pure]]
bool operator!=(
const acl& lhs,
const acl& rhs);
216 std::ostream& operator<<(std::ostream&,
const acl&);
218 std::string to_string(
const acl&
self);
247 using result_type = std::size_t;
acl()=default
Create an empty ACL. Keep in mind that an empty ACL is an illegal ACL.
void push_back(acl_rule &&x)
const acl_rule & operator[](size_type idx) const
static const acl & read_unsafe()
This ACL gives the world the ability to read.
const acl_rule & at(size_type idx) const
You can alter permissions on this node.
void emplace_back(TArgs &&...args)
Construct a rule emplace on the end of the list using args.
An individual rule in an acl.
const permission & permissions() const
The permissions associated with this ACL.
constexpr bool allows(permission self, permission perform)
Check that self allows it perform all operations.
static const acl & creator_all()
This ACL gives the creators authentication id's all permissions.
No permissions are set (server could have been configured without ACL support).
static const acl & open_unsafe()
This is a completely open ACL.
void reserve(size_type capacity)
Increase the reserved memory block so it can store at least capacity rules without reallocating...
You can create a child node.
You can access the data of a node and can list its children.
size_type size() const
The number of rules in this ACL.
const std::string & id() const
The ID of the user under the scheme.
const std::string & scheme() const
The authentication scheme this list is used for.
permission
Describes the ability of a user to perform a certain action.
An access control list is a wrapper around acl_rule instances.
acl(std::initializer_list< acl_rule > rules)
Create an instance with the provided rules.
You can erase a child node (but not necessarily this one).
constexpr permission operator|(permission a, permission b)
Set union operation of permission.
constexpr permission operator&(permission a, permission b)
Set intersection operation of permission.
You can set the data of a node.
constexpr permission operator~(permission a)
Set inverse operation of permission.
acl_rule(std::string scheme, std::string id, permission permissions)
Create an ACL under the given scheme and id with the given permissions.
std::size_t hash(const acl_rule &self)
Compute a hash for the given rule.