oxide_api/silos.rs
1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Silos {
6 pub client: Client,
7}
8
9impl Silos {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Silos { client }
13 }
14
15 /**
16 * Fetch the current silo's IAM policy.
17 *
18 * This function performs a `GET` to the `/policy` endpoint.
19 */
20 pub async fn policy_get(&self) -> Result<crate::types::SiloRolePolicy> {
21 let url = "/policy".to_string();
22 self.client.get(&url, None).await
23 }
24
25 /**
26 * Update the current silo's IAM policy.
27 *
28 * This function performs a `PUT` to the `/policy` endpoint.
29 */
30 pub async fn policy_put(
31 &self,
32 body: &crate::types::SiloRolePolicy,
33 ) -> Result<crate::types::SiloRolePolicy> {
34 let url = "/policy".to_string();
35 self.client
36 .put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
37 .await
38 }
39
40 /**
41 * List silos.
42 *
43 * This function performs a `GET` to the `/silos` endpoint.
44 *
45 * Lists silos that are discoverable based on the current permissions.
46 *
47 * **Parameters:**
48 *
49 * * `limit: u32` -- Maximum number of items returned by a single call.
50 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
51 * * `sort_by: crate::types::NameOrIdSortMode` -- Supported set of sort modes for scanning by name or id.
52 */
53 pub async fn get_page(
54 &self,
55 limit: u32,
56 page_token: &str,
57 sort_by: crate::types::NameOrIdSortMode,
58 ) -> Result<Vec<crate::types::Silo>> {
59 let mut query_args: Vec<(String, String)> = Default::default();
60 if !limit.to_string().is_empty() {
61 query_args.push(("limit".to_string(), limit.to_string()));
62 }
63 if !page_token.is_empty() {
64 query_args.push(("page_token".to_string(), page_token.to_string()));
65 }
66 if !sort_by.to_string().is_empty() {
67 query_args.push(("sort_by".to_string(), sort_by.to_string()));
68 }
69 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
70 let url = format!("/silos?{}", query_);
71
72 let resp: crate::types::SiloResultsPage = self.client.get(&url, None).await?;
73
74 // Return our response data.
75 Ok(resp.items)
76 }
77
78 /**
79 * List silos.
80 *
81 * This function performs a `GET` to the `/silos` endpoint.
82 *
83 * As opposed to `get`, this function returns all the pages of the request at once.
84 *
85 * Lists silos that are discoverable based on the current permissions.
86 */
87 pub async fn get_all(
88 &self,
89 sort_by: crate::types::NameOrIdSortMode,
90 ) -> Result<Vec<crate::types::Silo>> {
91 let mut query_args: Vec<(String, String)> = Default::default();
92 if !sort_by.to_string().is_empty() {
93 query_args.push(("sort_by".to_string(), sort_by.to_string()));
94 }
95 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
96 let url = format!("/silos?{}", query_);
97
98 let mut resp: crate::types::SiloResultsPage = self.client.get(&url, None).await?;
99
100 let mut items = resp.items;
101 let mut page = resp.next_page;
102
103 // Paginate if we should.
104 while !page.is_empty() {
105 if !url.contains('?') {
106 resp = self
107 .client
108 .get(&format!("{}?page={}", url, page), None)
109 .await?;
110 } else {
111 resp = self
112 .client
113 .get(&format!("{}&page={}", url, page), None)
114 .await?;
115 }
116
117 items.append(&mut resp.items);
118
119 if !resp.next_page.is_empty() && resp.next_page != page {
120 page = resp.next_page.to_string();
121 } else {
122 page = "".to_string();
123 }
124 }
125
126 // Return our response data.
127 Ok(items)
128 }
129
130 /**
131 * Create a silo.
132 *
133 * This function performs a `POST` to the `/silos` endpoint.
134 */
135 pub async fn post(&self, body: &crate::types::SiloCreate) -> Result<crate::types::Silo> {
136 let url = "/silos".to_string();
137 self.client
138 .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
139 .await
140 }
141
142 /**
143 * Fetch a silo.
144 *
145 * This function performs a `GET` to the `/silos/{silo_name}` endpoint.
146 *
147 * Fetch a silo by name.
148 *
149 * **Parameters:**
150 *
151 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
152 */
153 pub async fn get(&self, silo_name: &str) -> Result<crate::types::Silo> {
154 let url = format!(
155 "/silos/{}",
156 crate::progenitor_support::encode_path(silo_name),
157 );
158
159 self.client.get(&url, None).await
160 }
161
162 /**
163 * Delete a silo.
164 *
165 * This function performs a `DELETE` to the `/silos/{silo_name}` endpoint.
166 *
167 * Delete a silo by name.
168 *
169 * **Parameters:**
170 *
171 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
172 */
173 pub async fn delete(&self, silo_name: &str) -> Result<()> {
174 let url = format!(
175 "/silos/{}",
176 crate::progenitor_support::encode_path(silo_name),
177 );
178
179 self.client.delete(&url, None).await
180 }
181
182 /**
183 * List a silo's IDPs.
184 *
185 * This function performs a `GET` to the `/silos/{silo_name}/identity-providers` endpoint.
186 *
187 * **Parameters:**
188 *
189 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
190 * * `limit: u32` -- Maximum number of items returned by a single call.
191 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
192 * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
193 *
194 * Currently, we only support scanning in ascending order.
195 */
196 pub async fn get_identity_providers(
197 &self,
198 limit: u32,
199 page_token: &str,
200 silo_name: &str,
201 sort_by: crate::types::NameSortMode,
202 ) -> Result<Vec<crate::types::IdentityProvider>> {
203 let mut query_args: Vec<(String, String)> = Default::default();
204 if !limit.to_string().is_empty() {
205 query_args.push(("limit".to_string(), limit.to_string()));
206 }
207 if !page_token.is_empty() {
208 query_args.push(("page_token".to_string(), page_token.to_string()));
209 }
210 if !sort_by.to_string().is_empty() {
211 query_args.push(("sort_by".to_string(), sort_by.to_string()));
212 }
213 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
214 let url = format!(
215 "/silos/{}/identity-providers?{}",
216 crate::progenitor_support::encode_path(silo_name),
217 query_
218 );
219
220 let resp: crate::types::IdentityProviderResultsPage = self.client.get(&url, None).await?;
221
222 // Return our response data.
223 Ok(resp.items)
224 }
225
226 /**
227 * List a silo's IDPs.
228 *
229 * This function performs a `GET` to the `/silos/{silo_name}/identity-providers` endpoint.
230 *
231 * As opposed to `get_identity_providers`, this function returns all the pages of the request at once.
232 */
233 pub async fn get_all_identity_providers(
234 &self,
235 silo_name: &str,
236 sort_by: crate::types::NameSortMode,
237 ) -> Result<Vec<crate::types::IdentityProvider>> {
238 let mut query_args: Vec<(String, String)> = Default::default();
239 if !sort_by.to_string().is_empty() {
240 query_args.push(("sort_by".to_string(), sort_by.to_string()));
241 }
242 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
243 let url = format!(
244 "/silos/{}/identity-providers?{}",
245 crate::progenitor_support::encode_path(silo_name),
246 query_
247 );
248
249 let mut resp: crate::types::IdentityProviderResultsPage =
250 self.client.get(&url, None).await?;
251
252 let mut items = resp.items;
253 let mut page = resp.next_page;
254
255 // Paginate if we should.
256 while !page.is_empty() {
257 if !url.contains('?') {
258 resp = self
259 .client
260 .get(&format!("{}?page={}", url, page), None)
261 .await?;
262 } else {
263 resp = self
264 .client
265 .get(&format!("{}&page={}", url, page), None)
266 .await?;
267 }
268
269 items.append(&mut resp.items);
270
271 if !resp.next_page.is_empty() && resp.next_page != page {
272 page = resp.next_page.to_string();
273 } else {
274 page = "".to_string();
275 }
276 }
277
278 // Return our response data.
279 Ok(items)
280 }
281
282 /**
283 * Fetch a silo's IAM policy.
284 *
285 * This function performs a `GET` to the `/silos/{silo_name}/policy` endpoint.
286 *
287 * **Parameters:**
288 *
289 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
290 */
291 pub async fn get_policy(&self, silo_name: &str) -> Result<crate::types::SiloRolePolicy> {
292 let url = format!(
293 "/silos/{}/policy",
294 crate::progenitor_support::encode_path(silo_name),
295 );
296
297 self.client.get(&url, None).await
298 }
299
300 /**
301 * Update a silo's IAM policy.
302 *
303 * This function performs a `PUT` to the `/silos/{silo_name}/policy` endpoint.
304 *
305 * **Parameters:**
306 *
307 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
308 */
309 pub async fn put_policy(
310 &self,
311 silo_name: &str,
312 body: &crate::types::SiloRolePolicy,
313 ) -> Result<crate::types::SiloRolePolicy> {
314 let url = format!(
315 "/silos/{}/policy",
316 crate::progenitor_support::encode_path(silo_name),
317 );
318
319 self.client
320 .put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
321 .await
322 }
323
324 /**
325 * Create a SAML IDP.
326 *
327 * This function performs a `POST` to the `/silos/{silo_name}/saml-identity-providers` endpoint.
328 *
329 * **Parameters:**
330 *
331 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
332 */
333 pub async fn saml_idp_fetch(
334 &self,
335 silo_name: &str,
336 body: &crate::types::SamlIdentityProviderCreate,
337 ) -> Result<crate::types::SamlIdentityProvider> {
338 let url = format!(
339 "/silos/{}/saml-identity-providers",
340 crate::progenitor_support::encode_path(silo_name),
341 );
342
343 self.client
344 .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
345 .await
346 }
347
348 /**
349 * Fetch a SAML IDP.
350 *
351 * This function performs a `GET` to the `/silos/{silo_name}/saml-identity-providers/{provider_name}` endpoint.
352 *
353 * **Parameters:**
354 *
355 * * `provider_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
356 * * `silo_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
357 */
358 pub async fn saml_idp_create(
359 &self,
360 provider_name: &str,
361 silo_name: &str,
362 ) -> Result<crate::types::SamlIdentityProvider> {
363 let url = format!(
364 "/silos/{}/saml-identity-providers/{}",
365 crate::progenitor_support::encode_path(silo_name),
366 crate::progenitor_support::encode_path(provider_name),
367 );
368
369 self.client.get(&url, None).await
370 }
371
372 /**
373 * List users.
374 *
375 * This function performs a `GET` to the `/users` endpoint.
376 *
377 * **Parameters:**
378 *
379 * * `limit: u32` -- Maximum number of items returned by a single call.
380 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
381 * * `sort_by: crate::types::IdSortMode` -- Supported set of sort modes for scanning by id only.
382 *
383 * Currently, we only support scanning in ascending order.
384 */
385 pub async fn users_get(
386 &self,
387 limit: u32,
388 page_token: &str,
389 sort_by: crate::types::IdSortMode,
390 ) -> Result<Vec<crate::types::User>> {
391 let mut query_args: Vec<(String, String)> = Default::default();
392 if !limit.to_string().is_empty() {
393 query_args.push(("limit".to_string(), limit.to_string()));
394 }
395 if !page_token.is_empty() {
396 query_args.push(("page_token".to_string(), page_token.to_string()));
397 }
398 if !sort_by.to_string().is_empty() {
399 query_args.push(("sort_by".to_string(), sort_by.to_string()));
400 }
401 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
402 let url = format!("/users?{}", query_);
403
404 let resp: crate::types::UserResultsPage = self.client.get(&url, None).await?;
405
406 // Return our response data.
407 Ok(resp.items)
408 }
409
410 /**
411 * List users.
412 *
413 * This function performs a `GET` to the `/users` endpoint.
414 *
415 * As opposed to `users_get`, this function returns all the pages of the request at once.
416 */
417 pub async fn users_get_all(
418 &self,
419 sort_by: crate::types::IdSortMode,
420 ) -> Result<Vec<crate::types::User>> {
421 let mut query_args: Vec<(String, String)> = Default::default();
422 if !sort_by.to_string().is_empty() {
423 query_args.push(("sort_by".to_string(), sort_by.to_string()));
424 }
425 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
426 let url = format!("/users?{}", query_);
427
428 let mut resp: crate::types::UserResultsPage = self.client.get(&url, None).await?;
429
430 let mut items = resp.items;
431 let mut page = resp.next_page;
432
433 // Paginate if we should.
434 while !page.is_empty() {
435 if !url.contains('?') {
436 resp = self
437 .client
438 .get(&format!("{}?page={}", url, page), None)
439 .await?;
440 } else {
441 resp = self
442 .client
443 .get(&format!("{}&page={}", url, page), None)
444 .await?;
445 }
446
447 items.append(&mut resp.items);
448
449 if !resp.next_page.is_empty() && resp.next_page != page {
450 page = resp.next_page.to_string();
451 } else {
452 page = "".to_string();
453 }
454 }
455
456 // Return our response data.
457 Ok(items)
458 }
459}