use std::collections::HashSet;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Permissions {
pub read_only: bool,
pub allowed_commands: Option<HashSet<String>>,
pub sensitive_commands: HashSet<String>,
pub confirmation_token: Option<String>,
}
impl Default for Permissions {
fn default() -> Self {
Self {
read_only: true,
allowed_commands: None,
sensitive_commands: HashSet::new(),
confirmation_token: None,
}
}
}
impl Permissions {
pub fn read_write() -> Self {
Self {
read_only: false,
..Self::default()
}
}
pub fn allow_commands<I, S>(mut self, commands: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.allowed_commands = Some(commands.into_iter().map(Into::into).collect());
self
}
pub fn confirm<I, S>(mut self, commands: I, token: impl Into<String>) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.sensitive_commands = commands.into_iter().map(Into::into).collect();
self.confirmation_token = Some(token.into());
self
}
pub fn require_confirmation<I, S>(mut self, commands: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.sensitive_commands = commands.into_iter().map(Into::into).collect();
self.confirmation_token = None;
self
}
}