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