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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use super::{Principal, Property, Type, ACL, DKIM};
use crate::{core::set::SetObject, Get, Set};
use ahash::AHashMap;
impl Principal<Set> {
pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
self.name = name.into().into();
self
}
pub fn description(&mut self, description: Option<impl Into<String>>) -> &mut Self {
self.description = description.map(|s| s.into());
self
}
pub fn email(&mut self, email: impl Into<String>) -> &mut Self {
self.email = email.into().into();
self
}
pub fn secret(&mut self, secret: impl Into<String>) -> &mut Self {
self.secret = secret.into().into();
self
}
pub fn timezone(&mut self, timezone: Option<impl Into<String>>) -> &mut Self {
self.timezone = timezone.map(|s| s.into());
self
}
pub fn picture(&mut self, picture: Option<impl Into<String>>) -> &mut Self {
self.picture = picture.map(|s| s.into());
self
}
pub fn quota(&mut self, quota: Option<u32>) -> &mut Self {
self.quota = quota;
self
}
pub fn ptype(&mut self, ptype: Type) -> &mut Self {
self.ptype = ptype.into();
self
}
pub fn dkim(&mut self, dkim: DKIM) -> &mut Self {
self.dkim = dkim.into();
self
}
pub fn acl(&mut self, acl: Option<AHashMap<String, Vec<ACL>>>) -> &mut Self {
self.acl = acl;
self
}
pub fn aliases<T, U>(&mut self, aliases: Option<T>) -> &mut Self
where
T: IntoIterator<Item = U>,
U: Into<String>,
{
self.aliases = aliases.map(|l| l.into_iter().map(|v| v.into()).collect());
self
}
pub fn alias(&mut self, alias: &str, set: bool) -> &mut Self {
self.property_patch
.get_or_insert_with(AHashMap::new)
.insert(format!("{}/{}", Property::Aliases, alias), set);
self
}
pub fn capabilities<T, U>(&mut self, capabilities: Option<T>) -> &mut Self
where
T: IntoIterator<Item = U>,
U: Into<String>,
{
self.capabilities = capabilities.map(|l| l.into_iter().map(|v| v.into()).collect());
self
}
pub fn members<T, U>(&mut self, members: Option<T>) -> &mut Self
where
T: IntoIterator<Item = U>,
U: Into<String>,
{
self.members = members.map(|l| l.into_iter().map(|v| v.into()).collect());
self
}
pub fn member(&mut self, member: &str, set: bool) -> &mut Self {
self.property_patch
.get_or_insert_with(AHashMap::new)
.insert(format!("{}/{}", Property::Members, member), set);
self
}
}
impl SetObject for Principal<Set> {
type SetArguments = ();
fn new(_create_id: Option<usize>) -> Self {
Principal {
_create_id,
_state: Default::default(),
id: None,
ptype: None,
name: "".to_string().into(),
description: "".to_string().into(),
email: "".to_string().into(),
timezone: "".to_string().into(),
capabilities: Vec::with_capacity(0).into(),
aliases: Vec::with_capacity(0).into(),
secret: "".to_string().into(),
dkim: None,
quota: None,
picture: "".to_string().into(),
members: Vec::with_capacity(0).into(),
acl: AHashMap::with_capacity(0).into(),
property_patch: None,
}
}
fn create_id(&self) -> Option<String> {
self._create_id.map(|id| format!("c{}", id))
}
}
impl SetObject for Principal<Get> {
type SetArguments = ();
fn new(_create_id: Option<usize>) -> Self {
unimplemented!()
}
fn create_id(&self) -> Option<String> {
None
}
}