1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ConvertUserToGroupError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteUserError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetUserError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum OffboardPreviewError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum OffboardWorkspaceUserError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UpdateUserError {
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn convert_user_to_group(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<String, Error<ConvertUserToGroupError>> {
62 let local_var_configuration = configuration;
63
64 let local_var_client = &local_var_configuration.client;
65
66 let local_var_uri_str = format!("{}/w/{workspace}/users/convert_to_group/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
67 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
68
69 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
71 }
72 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
73 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
74 };
75
76 let local_var_req = local_var_req_builder.build()?;
77 let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79 let local_var_status = local_var_resp.status();
80 let local_var_content = local_var_resp.text().await?;
81
82 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83 crate::from_str_patched(&local_var_content).map_err(Error::from)
84 } else {
85 let local_var_entity: Option<ConvertUserToGroupError> = crate::from_str_patched(&local_var_content).ok();
86 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
87 Err(Error::ResponseError(local_var_error))
88 }
89}
90
91pub async fn delete_user(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<String, Error<DeleteUserError>> {
92 let local_var_configuration = configuration;
93
94 let local_var_client = &local_var_configuration.client;
95
96 let local_var_uri_str = format!("{}/w/{workspace}/users/delete/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
97 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
98
99 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101 }
102 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
103 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
104 };
105
106 let local_var_req = local_var_req_builder.build()?;
107 let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109 let local_var_status = local_var_resp.status();
110 let local_var_content = local_var_resp.text().await?;
111
112 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113 crate::from_str_patched(&local_var_content).map_err(Error::from)
114 } else {
115 let local_var_entity: Option<DeleteUserError> = crate::from_str_patched(&local_var_content).ok();
116 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117 Err(Error::ResponseError(local_var_error))
118 }
119}
120
121pub async fn get_user(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<models::User, Error<GetUserError>> {
122 let local_var_configuration = configuration;
123
124 let local_var_client = &local_var_configuration.client;
125
126 let local_var_uri_str = format!("{}/w/{workspace}/users/get/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
127 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
128
129 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
130 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
131 }
132 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
133 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
134 };
135
136 let local_var_req = local_var_req_builder.build()?;
137 let local_var_resp = local_var_client.execute(local_var_req).await?;
138
139 let local_var_status = local_var_resp.status();
140 let local_var_content = local_var_resp.text().await?;
141
142 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
143 crate::from_str_patched(&local_var_content).map_err(Error::from)
144 } else {
145 let local_var_entity: Option<GetUserError> = crate::from_str_patched(&local_var_content).ok();
146 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
147 Err(Error::ResponseError(local_var_error))
148 }
149}
150
151pub async fn offboard_preview(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<models::OffboardPreview, Error<OffboardPreviewError>> {
152 let local_var_configuration = configuration;
153
154 let local_var_client = &local_var_configuration.client;
155
156 let local_var_uri_str = format!("{}/w/{workspace}/users/offboard_preview/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
157 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
158
159 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
160 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
161 }
162 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
163 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
164 };
165
166 let local_var_req = local_var_req_builder.build()?;
167 let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169 let local_var_status = local_var_resp.status();
170 let local_var_content = local_var_resp.text().await?;
171
172 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173 crate::from_str_patched(&local_var_content).map_err(Error::from)
174 } else {
175 let local_var_entity: Option<OffboardPreviewError> = crate::from_str_patched(&local_var_content).ok();
176 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177 Err(Error::ResponseError(local_var_error))
178 }
179}
180
181pub async fn offboard_workspace_user(configuration: &configuration::Configuration, workspace: &str, username: &str, offboard_request: models::OffboardRequest) -> Result<models::OffboardResponse, Error<OffboardWorkspaceUserError>> {
182 let local_var_configuration = configuration;
183
184 let local_var_client = &local_var_configuration.client;
185
186 let local_var_uri_str = format!("{}/w/{workspace}/users/offboard/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
187 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
188
189 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
190 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191 }
192 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
193 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
194 };
195 local_var_req_builder = local_var_req_builder.json(&offboard_request);
196
197 let local_var_req = local_var_req_builder.build()?;
198 let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200 let local_var_status = local_var_resp.status();
201 let local_var_content = local_var_resp.text().await?;
202
203 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204 crate::from_str_patched(&local_var_content).map_err(Error::from)
205 } else {
206 let local_var_entity: Option<OffboardWorkspaceUserError> = crate::from_str_patched(&local_var_content).ok();
207 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208 Err(Error::ResponseError(local_var_error))
209 }
210}
211
212pub async fn update_user(configuration: &configuration::Configuration, workspace: &str, username: &str, edit_workspace_user: models::EditWorkspaceUser) -> Result<String, Error<UpdateUserError>> {
213 let local_var_configuration = configuration;
214
215 let local_var_client = &local_var_configuration.client;
216
217 let local_var_uri_str = format!("{}/w/{workspace}/users/update/{username}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), username=crate::apis::urlencode(username));
218 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
219
220 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222 }
223 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
224 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
225 };
226 local_var_req_builder = local_var_req_builder.json(&edit_workspace_user);
227
228 let local_var_req = local_var_req_builder.build()?;
229 let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231 let local_var_status = local_var_resp.status();
232 let local_var_content = local_var_resp.text().await?;
233
234 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235 crate::from_str_patched(&local_var_content).map_err(Error::from)
236 } else {
237 let local_var_entity: Option<UpdateUserError> = crate::from_str_patched(&local_var_content).ok();
238 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239 Err(Error::ResponseError(local_var_error))
240 }
241}
242