openauth_plugins/access/
types.rs1use std::collections::{BTreeMap, BTreeSet};
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum Connector {
6 And,
8 Or,
10}
11
12pub type Statements = BTreeMap<String, BTreeSet<String>>;
14
15pub type AccessRequest = BTreeMap<String, ResourceRequest>;
17
18#[derive(Clone, Debug, Eq, PartialEq)]
20pub struct ResourceRequest {
21 pub(crate) actions: BTreeSet<String>,
22 pub(crate) connector: Connector,
23}
24
25impl ResourceRequest {
26 pub fn all<I, S>(actions: I) -> Self
28 where
29 I: IntoIterator<Item = S>,
30 S: Into<String>,
31 {
32 Self {
33 actions: actions.into_iter().map(Into::into).collect(),
34 connector: Connector::And,
35 }
36 }
37
38 pub fn any<I, S>(actions: I) -> Self
40 where
41 I: IntoIterator<Item = S>,
42 S: Into<String>,
43 {
44 Self {
45 actions: actions.into_iter().map(Into::into).collect(),
46 connector: Connector::Or,
47 }
48 }
49
50 pub(crate) fn actions(&self) -> &BTreeSet<String> {
51 &self.actions
52 }
53
54 pub(crate) fn connector(&self) -> Connector {
55 self.connector
56 }
57}
58
59#[derive(Clone, Debug, Eq, PartialEq)]
61pub struct Role {
62 pub(crate) statements: Statements,
63}
64
65impl Role {
66 pub(crate) fn new(statements: Statements) -> Self {
67 Self { statements }
68 }
69
70 pub fn statements(&self) -> &Statements {
72 &self.statements
73 }
74}