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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::authentication_api::{self as api};
use antimatter_api::models::{
DomainIdentityGroupProviderDetails, DomainIdentityProviderDetails, DomainIdentityProviderInfo,
DomainIdentityProviderList, DomainIdentityProviderPrincipalList,
DomainIdentityProviderPrincipalParams, DomainInsertIdentityProviderPrincipal200Response,
PrincipalSummary, UpdatePrincipalParams,
};
impl Session {
/// Upsert an identity provider's configuration for the session's domain.
///
/// Arguments:
///
/// * `name` - A &str containing the identity provider's name.
/// * `domain_identity_provider` - A DomainIdentityProviderDetails
/// containing the identity providers configuration.
///
/// Returns:
///
/// A `Result` containing a `DomainIdentityProviderInfo` confirming the
/// upserted identity provider's configuration.
pub fn upsert_identity_providers(
&mut self,
name: &str,
domain_identity_provider: DomainIdentityProviderDetails,
) -> Result<DomainIdentityProviderInfo, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_upsert_identity_provider(
&conf,
self.get_domain_id().as_str(),
name,
domain_identity_provider,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Fetches a list of identity providers for session's domain.
///
/// Returns:
///
/// A `Result` containing a `DomainIdentityProviderList` a vector of
/// `DomainIdentityProviderInfo`.
pub fn list_identity_providers(&mut self) -> Result<DomainIdentityProviderList, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_list_identity_providers(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Lists the identity group providers.
///
/// Returns:
///
/// A `Result` containing a `DomainIdentityGroupProviderDetails` a list of IDP details.
pub fn list_identity_group_providers(
&mut self,
) -> Result<DomainIdentityGroupProviderDetails, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_identity_group_providers(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Fetches an identity providers information in session's domain.
///
/// Returns:
///
/// A `Result` containing a `DomainIdentityProviderInfo` confirming the
/// upserted identity provider's configuration.
pub fn get_identity_provider(
&mut self,
provider_name: &str,
) -> Result<DomainIdentityProviderInfo, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_identity_provider(
&conf,
self.get_domain_id().as_str(),
provider_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Create an identity provider principal for the session's domain for the
/// identity provider.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider
/// principal's name.
/// * `domain_identity_provider_principal_params` - A
/// DomainIdentityProviderPrincipalParams containing the identity
/// providers principal's configuration.
pub fn insert_identity_provider_principal(
&mut self,
identity_provider_name: &str,
domain_identity_provider_principal_params: DomainIdentityProviderPrincipalParams,
) -> Result<DomainInsertIdentityProviderPrincipal200Response, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_insert_identity_provider_principal(
&conf,
self.get_domain_id().as_str(),
identity_provider_name,
domain_identity_provider_principal_params,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Update an identity provider principal's capabilities in the session's
/// domain in the identity provider.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider's
/// name.
/// * `principal_id` - A &str containing the identity provider principal's
/// name.
/// * `update_principal_params` - New principal settings to apply to principal.
pub fn update_identity_provider_principal(
&mut self,
identity_provider_name: &str,
principal_id: &str,
capability_list: UpdatePrincipalParams,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_update_identity_provider_principal(
&conf,
self.get_domain_id().as_str(),
identity_provider_name,
principal_id,
capability_list,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Fetches a list of identity provider principal's of an identity provider
/// in the session's domain.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider's
/// name.
///
/// Returns:
///
/// A `Result` containing a `DomainIdentityProviderPrincipalList` with a
/// vector of identity provider principals.
pub fn get_identity_provider_principals(
&mut self,
identity_provider_name: &str,
) -> Result<DomainIdentityProviderPrincipalList, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_identity_provider_principals(
&conf,
self.get_domain_id().as_str(),
identity_provider_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Fetches an identity provider principal of an identity provider
/// in the session's domain.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider's
/// name.
/// * `principal_id` - A &str containing the identity provider principal's
/// name.
///
/// Returns:
///
/// A `Result` containing a `PrincipalSummary` containing the identity
/// provider principal's information.
pub fn get_identity_provider_principal(
&mut self,
identity_provider_name: &str,
principal_id: &str,
) -> Result<PrincipalSummary, SessionError> {
// TODO: This is generator bugged where the "type" field is incorrectly
// consumed by the serdes. This issue was also run into with the Rust
// CLI. As a work around we will instead get all principals and ID
// match the one we are looking for.
// let conf = self.get_configuration()?;
//
// let res = api::domain_get_identity_provider_principal(
// &conf,
// self.get_domain_id().as_str(),
// identity_provider_name,
// principal_id,
// )
// .map_err(|e| SessionError::APIError(format!("{}", e)))?;
let principals = self
.get_identity_provider_principals(identity_provider_name)
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
let res = principals
.principals
.iter()
.find(|p| p.principal_id == principal_id);
if res.is_none() {
return Err(SessionError::APIError(format!("404 principal not found")));
}
Ok(res.unwrap().to_owned())
}
/// Deletes an identity provider in the session's domain.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider's
/// name.
pub fn delete_identity_provider(
&mut self,
identity_provider_name: &str,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_identity_provider(
&conf,
self.get_domain_id().as_str(),
identity_provider_name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Deletes an identity provider principal in an identity provider in the
/// session's domain.
///
/// Arguments:
///
/// * `identity_provider_name` - A &str containing the identity provider's
/// name.
/// * `principal_id` - A &str containing the identity provider principal's
/// name.
pub fn delete_identity_provider_principal(
&mut self,
identity_provider_name: &str,
provider_id: &str,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_identity_provider_principal(
&conf,
self.get_domain_id().as_str(),
identity_provider_name,
provider_id,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
}