1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddAuthKeyError {
22 Status403(models::UnauthorizedApiError),
23 Status404(models::NotFoundApiError),
24 DefaultResponse(models::ApiError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteAuthKeyError {
32 Status403(models::UnauthorizedApiError),
33 Status404(models::NotFoundApiError),
34 DefaultResponse(models::ApiError),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum EditAuthKeyError {
42 Status403(models::UnauthorizedApiError),
43 Status404(models::NotFoundApiError),
44 DefaultResponse(models::ApiError),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetAuthKeyByIdError {
52 Status403(models::UnauthorizedApiError),
53 Status404(models::NotFoundApiError),
54 DefaultResponse(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetAuthKeysError {
62 Status403(models::UnauthorizedApiError),
63 Status404(models::NotFoundApiError),
64 DefaultResponse(models::ApiError),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum SearchAuthKeysError {
72 Status403(models::UnauthorizedApiError),
73 Status404(models::NotFoundApiError),
74 DefaultResponse(models::ApiError),
75 UnknownValue(serde_json::Value),
76}
77
78
79pub async fn add_auth_key(configuration: &configuration::Configuration, user_id: &str, add_auth_key_request: Option<models::AddAuthKeyRequest>) -> Result<models::AddAuthKey200Response, Error<AddAuthKeyError>> {
80 let p_user_id = user_id;
82 let p_add_auth_key_request = add_auth_key_request;
83
84 let uri_str = format!("{}/auth_keys/add/{userId}", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
85 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
86
87 if let Some(ref user_agent) = configuration.user_agent {
88 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89 }
90 if let Some(ref apikey) = configuration.api_key {
91 let key = apikey.key.clone();
92 let value = match apikey.prefix {
93 Some(ref prefix) => format!("{} {}", prefix, key),
94 None => key,
95 };
96 req_builder = req_builder.header("Authorization", value);
97 };
98 req_builder = req_builder.json(&p_add_auth_key_request);
99
100 let req = req_builder.build()?;
101 let resp = configuration.client.execute(req).await?;
102
103 let status = resp.status();
104 let content_type = resp
105 .headers()
106 .get("content-type")
107 .and_then(|v| v.to_str().ok())
108 .unwrap_or("application/octet-stream");
109 let content_type = super::ContentType::from(content_type);
110
111 if !status.is_client_error() && !status.is_server_error() {
112 let content = resp.text().await?;
113 match content_type {
114 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AddAuthKey200Response`"))),
116 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AddAuthKey200Response`")))),
117 }
118 } else {
119 let content = resp.text().await?;
120 let entity: Option<AddAuthKeyError> = serde_json::from_str(&content).ok();
121 Err(Error::ResponseError(ResponseContent { status, content, entity }))
122 }
123}
124
125pub async fn delete_auth_key(configuration: &configuration::Configuration, auth_key_id: &str) -> Result<models::DeleteAuthKey200Response, Error<DeleteAuthKeyError>> {
126 let p_auth_key_id = auth_key_id;
128
129 let uri_str = format!("{}/auth_keys/delete/{authKeyId}", configuration.base_path, authKeyId=p_auth_key_id.to_string());
130 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
131
132 if let Some(ref user_agent) = configuration.user_agent {
133 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134 }
135 if let Some(ref apikey) = configuration.api_key {
136 let key = apikey.key.clone();
137 let value = match apikey.prefix {
138 Some(ref prefix) => format!("{} {}", prefix, key),
139 None => key,
140 };
141 req_builder = req_builder.header("Authorization", value);
142 };
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteAuthKey200Response`"))),
160 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteAuthKey200Response`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<DeleteAuthKeyError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168
169pub async fn edit_auth_key(configuration: &configuration::Configuration, auth_key_id: &str, edit_auth_key_request: Option<models::EditAuthKeyRequest>) -> Result<models::GetAuthKeyById200Response, Error<EditAuthKeyError>> {
170 let p_auth_key_id = auth_key_id;
172 let p_edit_auth_key_request = edit_auth_key_request;
173
174 let uri_str = format!("{}/auth_keys/edit/{authKeyId}", configuration.base_path, authKeyId=p_auth_key_id.to_string());
175 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
176
177 if let Some(ref user_agent) = configuration.user_agent {
178 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
179 }
180 if let Some(ref apikey) = configuration.api_key {
181 let key = apikey.key.clone();
182 let value = match apikey.prefix {
183 Some(ref prefix) => format!("{} {}", prefix, key),
184 None => key,
185 };
186 req_builder = req_builder.header("Authorization", value);
187 };
188 req_builder = req_builder.json(&p_edit_auth_key_request);
189
190 let req = req_builder.build()?;
191 let resp = configuration.client.execute(req).await?;
192
193 let status = resp.status();
194 let content_type = resp
195 .headers()
196 .get("content-type")
197 .and_then(|v| v.to_str().ok())
198 .unwrap_or("application/octet-stream");
199 let content_type = super::ContentType::from(content_type);
200
201 if !status.is_client_error() && !status.is_server_error() {
202 let content = resp.text().await?;
203 match content_type {
204 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
205 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAuthKeyById200Response`"))),
206 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetAuthKeyById200Response`")))),
207 }
208 } else {
209 let content = resp.text().await?;
210 let entity: Option<EditAuthKeyError> = serde_json::from_str(&content).ok();
211 Err(Error::ResponseError(ResponseContent { status, content, entity }))
212 }
213}
214
215pub async fn get_auth_key_by_id(configuration: &configuration::Configuration, auth_key_id: &str) -> Result<models::GetAuthKeyById200Response, Error<GetAuthKeyByIdError>> {
216 let p_auth_key_id = auth_key_id;
218
219 let uri_str = format!("{}/auth_keys/view/{authKeyId}", configuration.base_path, authKeyId=p_auth_key_id.to_string());
220 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
221
222 if let Some(ref user_agent) = configuration.user_agent {
223 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224 }
225 if let Some(ref apikey) = configuration.api_key {
226 let key = apikey.key.clone();
227 let value = match apikey.prefix {
228 Some(ref prefix) => format!("{} {}", prefix, key),
229 None => key,
230 };
231 req_builder = req_builder.header("Authorization", value);
232 };
233
234 let req = req_builder.build()?;
235 let resp = configuration.client.execute(req).await?;
236
237 let status = resp.status();
238 let content_type = resp
239 .headers()
240 .get("content-type")
241 .and_then(|v| v.to_str().ok())
242 .unwrap_or("application/octet-stream");
243 let content_type = super::ContentType::from(content_type);
244
245 if !status.is_client_error() && !status.is_server_error() {
246 let content = resp.text().await?;
247 match content_type {
248 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAuthKeyById200Response`"))),
250 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetAuthKeyById200Response`")))),
251 }
252 } else {
253 let content = resp.text().await?;
254 let entity: Option<GetAuthKeyByIdError> = serde_json::from_str(&content).ok();
255 Err(Error::ResponseError(ResponseContent { status, content, entity }))
256 }
257}
258
259pub async fn get_auth_keys(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetAuthKeys200ResponseInner>, Error<GetAuthKeysError>> {
260
261 let uri_str = format!("{}/auth_keys", configuration.base_path);
262 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
263
264 if let Some(ref user_agent) = configuration.user_agent {
265 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
266 }
267 if let Some(ref apikey) = configuration.api_key {
268 let key = apikey.key.clone();
269 let value = match apikey.prefix {
270 Some(ref prefix) => format!("{} {}", prefix, key),
271 None => key,
272 };
273 req_builder = req_builder.header("Authorization", value);
274 };
275
276 let req = req_builder.build()?;
277 let resp = configuration.client.execute(req).await?;
278
279 let status = resp.status();
280 let content_type = resp
281 .headers()
282 .get("content-type")
283 .and_then(|v| v.to_str().ok())
284 .unwrap_or("application/octet-stream");
285 let content_type = super::ContentType::from(content_type);
286
287 if !status.is_client_error() && !status.is_server_error() {
288 let content = resp.text().await?;
289 match content_type {
290 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
291 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GetAuthKeys200ResponseInner>`"))),
292 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetAuthKeys200ResponseInner>`")))),
293 }
294 } else {
295 let content = resp.text().await?;
296 let entity: Option<GetAuthKeysError> = serde_json::from_str(&content).ok();
297 Err(Error::ResponseError(ResponseContent { status, content, entity }))
298 }
299}
300
301pub async fn search_auth_keys(configuration: &configuration::Configuration, search_auth_keys_request: Option<models::SearchAuthKeysRequest>) -> Result<Vec<models::GetAuthKeys200ResponseInner>, Error<SearchAuthKeysError>> {
302 let p_search_auth_keys_request = search_auth_keys_request;
304
305 let uri_str = format!("{}/auth_keys", configuration.base_path);
306 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
307
308 if let Some(ref user_agent) = configuration.user_agent {
309 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
310 }
311 if let Some(ref apikey) = configuration.api_key {
312 let key = apikey.key.clone();
313 let value = match apikey.prefix {
314 Some(ref prefix) => format!("{} {}", prefix, key),
315 None => key,
316 };
317 req_builder = req_builder.header("Authorization", value);
318 };
319 req_builder = req_builder.json(&p_search_auth_keys_request);
320
321 let req = req_builder.build()?;
322 let resp = configuration.client.execute(req).await?;
323
324 let status = resp.status();
325 let content_type = resp
326 .headers()
327 .get("content-type")
328 .and_then(|v| v.to_str().ok())
329 .unwrap_or("application/octet-stream");
330 let content_type = super::ContentType::from(content_type);
331
332 if !status.is_client_error() && !status.is_server_error() {
333 let content = resp.text().await?;
334 match content_type {
335 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
336 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GetAuthKeys200ResponseInner>`"))),
337 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetAuthKeys200ResponseInner>`")))),
338 }
339 } else {
340 let content = resp.text().await?;
341 let entity: Option<SearchAuthKeysError> = serde_json::from_str(&content).ok();
342 Err(Error::ResponseError(ResponseContent { status, content, entity }))
343 }
344}
345