use std::collections::{BTreeMap, BTreeSet};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Connector {
And,
Or,
}
pub type Statements = BTreeMap<String, BTreeSet<String>>;
pub type AccessRequest = BTreeMap<String, ResourceRequest>;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ResourceRequest {
pub(crate) actions: BTreeSet<String>,
pub(crate) connector: Connector,
}
impl ResourceRequest {
pub fn all<I, S>(actions: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
actions: actions.into_iter().map(Into::into).collect(),
connector: Connector::And,
}
}
pub fn any<I, S>(actions: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
actions: actions.into_iter().map(Into::into).collect(),
connector: Connector::Or,
}
}
pub(crate) fn actions(&self) -> &BTreeSet<String> {
&self.actions
}
pub(crate) fn connector(&self) -> Connector {
self.connector
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Role {
pub(crate) statements: Statements,
}
impl Role {
pub(crate) fn new(statements: Statements) -> Self {
Self { statements }
}
pub fn statements(&self) -> &Statements {
&self.statements
}
}