kanidm_client/
sync_account.rs
1use crate::{ClientError, KanidmClient};
2use kanidm_proto::constants::{ATTR_DESCRIPTION, ATTR_NAME};
3use kanidm_proto::v1::Entry;
4use std::collections::BTreeMap;
5use url::Url;
6
7impl KanidmClient {
8 pub async fn idm_sync_account_list(&self) -> Result<Vec<Entry>, ClientError> {
9 self.perform_get_request("/v1/sync_account").await
10 }
11
12 pub async fn idm_sync_account_get(&self, id: &str) -> Result<Option<Entry>, ClientError> {
13 self.perform_get_request(format!("/v1/sync_account/{}", id).as_str())
14 .await
15 }
16
17 pub async fn idm_sync_account_set_credential_portal(
18 &self,
19 id: &str,
20 url: Option<&Url>,
21 ) -> Result<(), ClientError> {
22 let m = if let Some(url) = url {
23 vec![url.to_owned()]
24 } else {
25 vec![]
26 };
27
28 self.perform_put_request(
29 format!("/v1/sync_account/{}/_attr/sync_credential_portal", id).as_str(),
30 m,
31 )
32 .await
33 }
34
35 pub async fn idm_sync_account_get_credential_portal(
36 &self,
37 id: &str,
38 ) -> Result<Option<Url>, ClientError> {
39 self.perform_get_request(
40 format!("/v1/sync_account/{}/_attr/sync_credential_portal", id).as_str(),
41 )
42 .await
43 .map(|values: Vec<Url>| values.first().cloned())
44 }
45
46 pub async fn idm_sync_account_set_yield_attributes(
47 &self,
48 id: &str,
49 attrs: &Vec<String>,
50 ) -> Result<(), ClientError> {
51 self.perform_put_request(
53 format!("/v1/sync_account/{}/_attr/sync_yield_authority", id).as_str(),
54 &attrs,
55 )
56 .await
57 }
58
59 pub async fn idm_sync_account_create(
60 &self,
61 name: &str,
62 description: Option<&str>,
63 ) -> Result<(), ClientError> {
64 let mut new_acct = Entry {
65 attrs: BTreeMap::new(),
66 };
67
68 new_acct
69 .attrs
70 .insert(ATTR_NAME.to_string(), vec![name.to_string()]);
71 if let Some(description) = description {
72 new_acct
73 .attrs
74 .insert(ATTR_DESCRIPTION.to_string(), vec![description.to_string()]);
75 }
76
77 self.perform_post_request("/v1/sync_account", new_acct)
78 .await
79 }
80
81 pub async fn idm_sync_account_generate_token(
83 &self,
84 id: &str,
85 label: &str,
86 ) -> Result<String, ClientError> {
87 self.perform_post_request(
88 format!("/v1/sync_account/{}/_sync_token", id).as_str(),
89 label,
90 )
91 .await
92 }
93
94 pub async fn idm_sync_account_destroy_token(&self, id: &str) -> Result<(), ClientError> {
95 self.perform_delete_request(format!("/v1/sync_account/{}/_sync_token", id,).as_str())
96 .await
97 }
98
99 pub async fn idm_sync_account_force_refresh(&self, id: &str) -> Result<(), ClientError> {
100 let mut update_entry = Entry {
101 attrs: BTreeMap::new(),
102 };
103
104 update_entry
105 .attrs
106 .insert("sync_cookie".to_string(), Vec::with_capacity(0));
107
108 self.perform_patch_request(format!("/v1/sync_account/{}", id).as_str(), update_entry)
109 .await
110 }
111
112 pub async fn idm_sync_account_finalise(&self, id: &str) -> Result<(), ClientError> {
113 self.perform_get_request(format!("/v1/sync_account/{}/_finalise", id).as_str())
114 .await
115 }
116
117 pub async fn idm_sync_account_terminate(&self, id: &str) -> Result<(), ClientError> {
118 self.perform_get_request(format!("/v1/sync_account/{}/_terminate", id).as_str())
119 .await
120 }
121}