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
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::{AddReadContext, ReadContextDetails, ReadContextList};
impl Session {
/// Fetches a list of all read contexts for the session's domain.
///
/// Returns:
///
/// A `Result` containing a `ReadContextList` with a vector of read context
/// information.
pub fn list_read_context(&mut self) -> Result<ReadContextList, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_list_read_contexts(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Creates a new read contexts for the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the read context's name.
/// * `add_read_context` - An AddReadContext containing the read
/// context's configuration.
pub fn add_read_context(
&mut self,
context_name: &str,
add_read_context: AddReadContext,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_upsert_read_context(
&conf,
self.get_domain_id().as_str(),
context_name,
add_read_context,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Get the information for a read context in the session's domain. It can
/// optionally return the policy bundle for the read context.
///
/// Arguments:
///
/// * `context_name` - A &str containing the read context's name.
/// * `include_policy_bundle` - An Option<bool> indicates whether the policy
/// bundle for the read context should also be returned.
///
/// Results:
/// A `Result` containing a `ReadContextDetails` with the read context's
/// information.
pub fn describe_read_context(
&mut self,
context_name: &str,
include_policy_bundle: Option<bool>,
) -> Result<ReadContextDetails, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_read_context(
&conf,
self.get_domain_id().as_str(),
context_name,
include_policy_bundle,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Delete a read context in the session's domain.
///
/// Arguments:
///
/// * `context_name` - A &str containing the read context's name.
pub fn delete_read_context(&mut self, context_name: &str) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_read_context(
&conf,
self.get_domain_id().as_str(),
context_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
}