windmill_api/apis/
admin_api.rs1use 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 UpdateUserError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn convert_user_to_group(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<String, Error<ConvertUserToGroupError>> {
48 let local_var_configuration = configuration;
49
50 let local_var_client = &local_var_configuration.client;
51
52 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));
53 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
54
55 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
56 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
57 }
58 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
59 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
60 };
61
62 let local_var_req = local_var_req_builder.build()?;
63 let local_var_resp = local_var_client.execute(local_var_req).await?;
64
65 let local_var_status = local_var_resp.status();
66 let local_var_content = local_var_resp.text().await?;
67
68 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69 crate::from_str_patched(&local_var_content).map_err(Error::from)
70 } else {
71 let local_var_entity: Option<ConvertUserToGroupError> = crate::from_str_patched(&local_var_content).ok();
72 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
73 Err(Error::ResponseError(local_var_error))
74 }
75}
76
77pub async fn delete_user(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<String, Error<DeleteUserError>> {
78 let local_var_configuration = configuration;
79
80 let local_var_client = &local_var_configuration.client;
81
82 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));
83 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
84
85 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
86 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
87 }
88 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
89 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
90 };
91
92 let local_var_req = local_var_req_builder.build()?;
93 let local_var_resp = local_var_client.execute(local_var_req).await?;
94
95 let local_var_status = local_var_resp.status();
96 let local_var_content = local_var_resp.text().await?;
97
98 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
99 crate::from_str_patched(&local_var_content).map_err(Error::from)
100 } else {
101 let local_var_entity: Option<DeleteUserError> = crate::from_str_patched(&local_var_content).ok();
102 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
103 Err(Error::ResponseError(local_var_error))
104 }
105}
106
107pub async fn get_user(configuration: &configuration::Configuration, workspace: &str, username: &str) -> Result<models::User, Error<GetUserError>> {
108 let local_var_configuration = configuration;
109
110 let local_var_client = &local_var_configuration.client;
111
112 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));
113 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
114
115 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
116 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
117 }
118 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
119 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
120 };
121
122 let local_var_req = local_var_req_builder.build()?;
123 let local_var_resp = local_var_client.execute(local_var_req).await?;
124
125 let local_var_status = local_var_resp.status();
126 let local_var_content = local_var_resp.text().await?;
127
128 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129 crate::from_str_patched(&local_var_content).map_err(Error::from)
130 } else {
131 let local_var_entity: Option<GetUserError> = crate::from_str_patched(&local_var_content).ok();
132 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
133 Err(Error::ResponseError(local_var_error))
134 }
135}
136
137pub async fn update_user(configuration: &configuration::Configuration, workspace: &str, username: &str, edit_workspace_user: models::EditWorkspaceUser) -> Result<String, Error<UpdateUserError>> {
138 let local_var_configuration = configuration;
139
140 let local_var_client = &local_var_configuration.client;
141
142 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));
143 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
149 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150 };
151 local_var_req_builder = local_var_req_builder.json(&edit_workspace_user);
152
153 let local_var_req = local_var_req_builder.build()?;
154 let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156 let local_var_status = local_var_resp.status();
157 let local_var_content = local_var_resp.text().await?;
158
159 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
160 crate::from_str_patched(&local_var_content).map_err(Error::from)
161 } else {
162 let local_var_entity: Option<UpdateUserError> = crate::from_str_patched(&local_var_content).ok();
163 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
164 Err(Error::ResponseError(local_var_error))
165 }
166}
167