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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::contexts_api::{self as api};
use antimatter_api::models::{
AddWriteContext, ClassifierRule, DomainGetWriteContextClassifierRules200Response,
DomainInsertWriteContextClassifierRule200Response, WriteContextConfigInfo, WriteContextDetails,
WriteContextList,
};
impl Session {
/// Create a new write context for the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
/// * `add_write_context` - An AddWriteContext containing the write
/// context's configuration.
pub fn add_write_context(
&mut self,
context_name: &str,
add_write_context: AddWriteContext,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_upsert_write_context(
&conf,
self.get_domain_id().as_str(),
context_name,
add_write_context,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Get a list of write contexts for the session's domain.
///
/// Returns:
///
/// A `Result` containing a `WriteContextList` with a vector of write
/// context information.
pub fn list_write_context(&mut self) -> Result<WriteContextList, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_list_write_contexts(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Get a write context's information for the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
///
/// Returns:
///
/// A `Result` containing a `WriteContextDetails` with information about
/// the write context.
pub fn describe_write_context(
&mut self,
context_name: &str,
) -> Result<WriteContextDetails, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_describe_write_context(
&conf,
self.get_domain_id().as_str(),
context_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Upserts a write context in the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
/// * `write_context_config_info` - A WriteContextConfigInfo containing
/// the write context's configuration.
pub fn upsert_write_context_configuration(
&mut self,
context_name: &str,
write_context_config_info: WriteContextConfigInfo,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_upsert_write_context_configuration(
&conf,
self.get_domain_id().as_str(),
context_name,
write_context_config_info,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Delete a write context from the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
pub fn delete_write_context(&mut self, context_name: &str) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_write_context(
&conf,
self.get_domain_id().as_str(),
context_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Get a list of classifier rules for a write context in the
/// session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name
///
/// Returns:
///
/// A `Result` containing a `DomainGetWriteContextClassifierRules200Response`
/// with a vector of classifier rules.
pub fn list_write_context_classifier_rules(
&mut self,
context_name: &str,
) -> Result<DomainGetWriteContextClassifierRules200Response, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_write_context_classifier_rules(
&conf,
self.get_domain_id().as_str(),
context_name,
))
.map_err(|e| SessionError::APIError(e.to_string()))?;
Ok(res)
}
/// Insert a classifier rule for a write context in the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
/// * `write_context_classifier_rule` - A ClassifierRule
/// containing the classifier rule's configuration.
pub fn insert_write_context_classifier_rule(
&mut self,
context_name: &str,
write_context_classifier_rule: ClassifierRule,
) -> Result<DomainInsertWriteContextClassifierRule200Response, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_insert_write_context_classifier_rule(
&conf,
self.get_domain_id().as_str(),
context_name,
write_context_classifier_rule,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Delete a classifier rule from a write context in the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
/// * `rule_id` - A &str containing the classifier rule's ID.
pub fn delete_write_context_classifier_rule(
&mut self,
context_name: &str,
rule_id: &str,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_write_context_classifier_rule(
&conf,
self.get_domain_id().as_str(),
context_name,
rule_id,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Delete all classifier rules from a write context in the
/// session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the write context's name.
pub fn delete_write_context_classifier_rules(
&mut self,
context_name: &str,
) -> Result<(), SessionError> {
let rule_list = self
.list_write_context_classifier_rules(context_name)
.map_err(|e| e)?;
for rule in rule_list.rules.unwrap_or_default().iter() {
self.delete_write_context_classifier_rule(
context_name,
rule.clone().id.unwrap().as_str(),
)
.map_err(|e| e)?;
}
Ok(())
}
}