1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
pub struct Policy {
pub permissions: Vec<Permission>,
}
impl Policy {
pub fn new(permissions: Vec<Permission>) -> Self {
Self { permissions }
}
pub fn public() -> Self {
Self::new(vec![Permission::new(
Identity::Anyone,
vec![Capability::Read, Capability::Write],
)])
}
}
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
pub struct Permission {
pub id: Identity,
pub capabilities: Vec<Capability>,
}
impl Permission {
pub fn new(id: Identity, capabilities: Vec<Capability>) -> Self {
Self { id, capabilities }
}
}
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum Identity {
User(String),
Anyone,
NoOne,
}
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum Capability {
Export,
Read,
Rotate,
Sign,
Write,
}