Skip to main content

cloudillo_types/
abac.rs

1// SPDX-FileCopyrightText: Szilárd Hajba
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4//! Attribute-based access control trait.
5
6/// Attribute set trait - all objects implement this
7pub trait AttrSet: Send + Sync {
8	/// Get a single string attribute
9	fn get(&self, key: &str) -> Option<&str>;
10
11	/// Get a list attribute
12	fn get_list(&self, key: &str) -> Option<Vec<&str>>;
13
14	/// Check if attribute equals value
15	fn has(&self, key: &str, value: &str) -> bool {
16		self.get(key) == Some(value)
17	}
18
19	/// Check if list attribute contains value
20	fn contains(&self, key: &str, value: &str) -> bool {
21		self.get_list(key).is_some_and(|list| list.contains(&value))
22	}
23}
24
25// vim: ts=4