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
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::encryption_api::{self as api};
use antimatter_api::models::{
ActiveRootEncryptionKeyId, AvailableRootEncryptionKeyProviders, KeyInfos,
RootEncryptionKeyIdResponse, RootEncryptionKeyItem, RootEncryptionKeyListResponse,
RootEncryptionKeyTestResponse, RotateKeyEncryptionKeyResponse,
};
use serde_json::Value;
impl Session {
/// Fetches the active root encryption key for the session's domain.
///
/// Returns:
///
/// A `Result` containing a `RootEncryptionKeyItem` with the root active
/// encryption key's information.
pub fn get_active_root_encryption_key(
&mut self,
) -> Result<RootEncryptionKeyItem, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_active_external_root_encryption_key(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Fetches the list of all root encryption key for the session's domain.
///
/// Returns:
///
/// A `Result` containing a `RootEncryptionKeyListResponse` with a vector of
/// root encryption key information.
pub fn list_root_encryption_keys(
&mut self,
) -> Result<RootEncryptionKeyListResponse, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_list_external_root_encryption_key(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Tests a root encryption key in the session's domain.
///
/// Returns:
///
/// A `Result` containing a `RootEncryptionKeyTestResponse` with the root
/// active encryption key's test result information.
pub fn test_root_encryption_key(
&mut self,
root_encryption_key_id: &str,
) -> Result<RootEncryptionKeyTestResponse, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_external_root_encryption_key_test(
&conf,
self.get_domain_id().as_str(),
root_encryption_key_id,
Value::Object(Default::default()),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Create a root encryption key in the session's domain.
///
/// Arguments:
///
/// * `key_infos` - A RootEncryptionKeyIdResponse containing the information
/// for the new root encryption key.
///
/// Returns:
///
/// A `Result` containing a `RootEncryptionKeyIdResponse` with the new root
/// encryption key's ID.
pub fn add_root_encryption_key(
&mut self,
key_infos: KeyInfos,
) -> Result<RootEncryptionKeyIdResponse, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_add_external_root_encryption_key(
&conf,
self.get_domain_id().as_str(),
key_infos,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Delete a root encryption key in the session's domain.
///
/// Arguments:
///
/// * `root_encryption_key_id` - A &str containing root encryption key's ID.
pub fn delete_root_encryption_key(
&mut self,
root_encryption_key_id: &str,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_external_root_encryption_key(
&conf,
self.get_domain_id().as_str(),
root_encryption_key_id,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Sets the active root encryption key in the session's domain.
///
/// Arguments:
///
/// * `root_encryption_key_id` - A &str containing root encryption key's ID.
pub fn set_active_root_encryption_key(
&mut self,
root_encryption_key_id: ActiveRootEncryptionKeyId,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_set_active_external_root_encryption_key(
&conf,
self.get_domain_id().as_str(),
root_encryption_key_id,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Rotates key encryption keys with the active root encryption key in the
/// session's domain.
///
/// Results:
///
/// A `Result` containing a `RotateKeyEncryptionKeyResponse` indicating if
/// there are more key encryption keys to rotate.
pub fn rotate_encryption_keys(
&mut self,
) -> Result<RotateKeyEncryptionKeyResponse, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_rotate_root_encryption_keys(
&conf,
self.get_domain_id().as_str(),
Value::Object(Default::default()),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Fetches a list of available root encryption key providers for the Cell.
///
/// Results:
///
/// A `Result` containing a `AvailableRootEncryptionKeyProviders` with a
/// vector of available root encryption key providers for the Cell.
pub fn list_key_providers(
&mut self,
) -> Result<AvailableRootEncryptionKeyProviders, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_external_root_encryption_key_providers(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
}