use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct RoleRule {
pub(super) prefix: String,
#[serde(default)]
pub(super) contains: Vec<String>,
pub(super) roles: Vec<String>,
}
impl RoleRule {
pub(super) fn covers(&self, tool: &str) -> bool {
tool.starts_with(self.prefix.as_str())
&& (self.contains.is_empty() || self.contains.iter().any(|c| tool.contains(c.as_str())))
}
pub(super) fn held_by<'r>(&self, roles: &'r [String]) -> Option<&'r str> {
roles
.iter()
.find(|role| self.roles.contains(role))
.map(String::as_str)
}
}