1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum DeleteServiceAccountError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum DeleteServiceAccountTokenError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetServiceAccountError {
49 Status400(models::JsonErrorResponseNull),
50 Status401(models::JsonErrorResponseNull),
51 Status403(models::JsonErrorResponseNull),
52 Status404(models::JsonErrorResponseNull),
53 Status409(models::JsonErrorResponseNull),
54 Status429(models::JsonErrorResponseNull),
55 Status500(models::JsonErrorResponseNull),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetServiceAccountTokensError {
63 Status400(models::JsonErrorResponseNull),
64 Status401(models::JsonErrorResponseNull),
65 Status403(models::JsonErrorResponseNull),
66 Status404(models::JsonErrorResponseNull),
67 Status409(models::JsonErrorResponseNull),
68 Status429(models::JsonErrorResponseNull),
69 Status500(models::JsonErrorResponseNull),
70 UnknownValue(serde_json::Value),
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum PostServiceAccountError {
77 Status400(models::JsonErrorResponseNull),
78 Status401(models::JsonErrorResponseNull),
79 Status403(models::JsonErrorResponseNull),
80 Status404(models::JsonErrorResponseNull),
81 Status409(models::JsonErrorResponseNull),
82 Status429(models::JsonErrorResponseNull),
83 Status500(models::JsonErrorResponseNull),
84 UnknownValue(serde_json::Value),
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum PostServiceAccountTokenError {
91 Status400(models::JsonErrorResponseNull),
92 Status401(models::JsonErrorResponseNull),
93 Status403(models::JsonErrorResponseNull),
94 Status404(models::JsonErrorResponseNull),
95 Status409(models::JsonErrorResponseNull),
96 Status429(models::JsonErrorResponseNull),
97 Status500(models::JsonErrorResponseNull),
98 UnknownValue(serde_json::Value),
99}
100
101pub async fn delete_service_account(
102 configuration: &configuration::Configuration,
103 sa_identifier: &str,
104) -> Result<(), Error<DeleteServiceAccountError>> {
105 let p_path_sa_identifier = sa_identifier;
107
108 let uri_str = format!(
109 "{}/service-accounts/{sa_identifier}",
110 configuration.base_path,
111 sa_identifier = crate::apis::urlencode(p_path_sa_identifier)
112 );
113 let mut req_builder = configuration
114 .client
115 .request(reqwest::Method::DELETE, &uri_str);
116
117 if let Some(ref apikey) = configuration.api_key {
118 let key = apikey.key.clone();
119 let value = match apikey.prefix {
120 Some(ref prefix) => format!("{} {}", prefix, key),
121 None => key,
122 };
123 req_builder = req_builder.query(&[("access_token", value)]);
124 }
125 if let Some(ref user_agent) = configuration.user_agent {
126 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127 }
128 if let Some(ref auth_conf) = configuration.basic_auth {
129 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
130 };
131 if let Some(ref token) = configuration.bearer_access_token {
132 req_builder = req_builder.bearer_auth(token.to_owned());
133 };
134
135 let req = req_builder.build()?;
136 let resp = configuration.client.execute(req).await?;
137
138 let status = resp.status();
139
140 if !status.is_client_error() && !status.is_server_error() {
141 Ok(())
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<DeleteServiceAccountError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent {
146 status,
147 content,
148 entity,
149 }))
150 }
151}
152
153pub async fn delete_service_account_token(
154 configuration: &configuration::Configuration,
155 sa_identifier: &str,
156 token_name: &str,
157) -> Result<(), Error<DeleteServiceAccountTokenError>> {
158 let p_path_sa_identifier = sa_identifier;
160 let p_path_token_name = token_name;
161
162 let uri_str = format!(
163 "{}/service-accounts/{sa_identifier}/tokens/{token_name}",
164 configuration.base_path,
165 sa_identifier = crate::apis::urlencode(p_path_sa_identifier),
166 token_name = crate::apis::urlencode(p_path_token_name)
167 );
168 let mut req_builder = configuration
169 .client
170 .request(reqwest::Method::DELETE, &uri_str);
171
172 if let Some(ref apikey) = configuration.api_key {
173 let key = apikey.key.clone();
174 let value = match apikey.prefix {
175 Some(ref prefix) => format!("{} {}", prefix, key),
176 None => key,
177 };
178 req_builder = req_builder.query(&[("access_token", value)]);
179 }
180 if let Some(ref user_agent) = configuration.user_agent {
181 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182 }
183 if let Some(ref auth_conf) = configuration.basic_auth {
184 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
185 };
186 if let Some(ref token) = configuration.bearer_access_token {
187 req_builder = req_builder.bearer_auth(token.to_owned());
188 };
189
190 let req = req_builder.build()?;
191 let resp = configuration.client.execute(req).await?;
192
193 let status = resp.status();
194
195 if !status.is_client_error() && !status.is_server_error() {
196 Ok(())
197 } else {
198 let content = resp.text().await?;
199 let entity: Option<DeleteServiceAccountTokenError> = serde_json::from_str(&content).ok();
200 Err(Error::ResponseError(ResponseContent {
201 status,
202 content,
203 entity,
204 }))
205 }
206}
207
208pub async fn get_service_account(
209 configuration: &configuration::Configuration,
210 sa_identifier: &str,
211) -> Result<models::UserModel, Error<GetServiceAccountError>> {
212 let p_path_sa_identifier = sa_identifier;
214
215 let uri_str = format!(
216 "{}/service-accounts/{sa_identifier}",
217 configuration.base_path,
218 sa_identifier = crate::apis::urlencode(p_path_sa_identifier)
219 );
220 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
221
222 if let Some(ref apikey) = configuration.api_key {
223 let key = apikey.key.clone();
224 let value = match apikey.prefix {
225 Some(ref prefix) => format!("{} {}", prefix, key),
226 None => key,
227 };
228 req_builder = req_builder.query(&[("access_token", value)]);
229 }
230 if let Some(ref user_agent) = configuration.user_agent {
231 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
232 }
233 if let Some(ref auth_conf) = configuration.basic_auth {
234 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
235 };
236 if let Some(ref token) = configuration.bearer_access_token {
237 req_builder = req_builder.bearer_auth(token.to_owned());
238 };
239
240 let req = req_builder.build()?;
241 let resp = configuration.client.execute(req).await?;
242
243 let status = resp.status();
244 let content_type = resp
245 .headers()
246 .get("content-type")
247 .and_then(|v| v.to_str().ok())
248 .unwrap_or("application/octet-stream");
249 let content_type = super::ContentType::from(content_type);
250
251 if !status.is_client_error() && !status.is_server_error() {
252 let content = resp.text().await?;
253 match content_type {
254 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserModel`"))),
256 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserModel`")))),
257 }
258 } else {
259 let content = resp.text().await?;
260 let entity: Option<GetServiceAccountError> = serde_json::from_str(&content).ok();
261 Err(Error::ResponseError(ResponseContent {
262 status,
263 content,
264 entity,
265 }))
266 }
267}
268
269pub async fn get_service_account_tokens(
270 configuration: &configuration::Configuration,
271 sa_identifier: &str,
272) -> Result<Vec<models::TokenModel>, Error<GetServiceAccountTokensError>> {
273 let p_path_sa_identifier = sa_identifier;
275
276 let uri_str = format!(
277 "{}/service-accounts/{sa_identifier}/tokens",
278 configuration.base_path,
279 sa_identifier = crate::apis::urlencode(p_path_sa_identifier)
280 );
281 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
282
283 if let Some(ref apikey) = configuration.api_key {
284 let key = apikey.key.clone();
285 let value = match apikey.prefix {
286 Some(ref prefix) => format!("{} {}", prefix, key),
287 None => key,
288 };
289 req_builder = req_builder.query(&[("access_token", value)]);
290 }
291 if let Some(ref user_agent) = configuration.user_agent {
292 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
293 }
294 if let Some(ref auth_conf) = configuration.basic_auth {
295 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
296 };
297 if let Some(ref token) = configuration.bearer_access_token {
298 req_builder = req_builder.bearer_auth(token.to_owned());
299 };
300
301 let req = req_builder.build()?;
302 let resp = configuration.client.execute(req).await?;
303
304 let status = resp.status();
305 let content_type = resp
306 .headers()
307 .get("content-type")
308 .and_then(|v| v.to_str().ok())
309 .unwrap_or("application/octet-stream");
310 let content_type = super::ContentType::from(content_type);
311
312 if !status.is_client_error() && !status.is_server_error() {
313 let content = resp.text().await?;
314 match content_type {
315 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
316 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TokenModel>`"))),
317 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TokenModel>`")))),
318 }
319 } else {
320 let content = resp.text().await?;
321 let entity: Option<GetServiceAccountTokensError> = serde_json::from_str(&content).ok();
322 Err(Error::ResponseError(ResponseContent {
323 status,
324 content,
325 entity,
326 }))
327 }
328}
329
330pub async fn post_service_account(
331 configuration: &configuration::Configuration,
332 sa_identifier: &str,
333 service_account_create_input: models::ServiceAccountCreateInput,
334) -> Result<models::UserModel, Error<PostServiceAccountError>> {
335 let p_path_sa_identifier = sa_identifier;
337 let p_body_service_account_create_input = service_account_create_input;
338
339 let uri_str = format!(
340 "{}/service-accounts/{sa_identifier}",
341 configuration.base_path,
342 sa_identifier = crate::apis::urlencode(p_path_sa_identifier)
343 );
344 let mut req_builder = configuration
345 .client
346 .request(reqwest::Method::POST, &uri_str);
347
348 if let Some(ref apikey) = configuration.api_key {
349 let key = apikey.key.clone();
350 let value = match apikey.prefix {
351 Some(ref prefix) => format!("{} {}", prefix, key),
352 None => key,
353 };
354 req_builder = req_builder.query(&[("access_token", value)]);
355 }
356 if let Some(ref user_agent) = configuration.user_agent {
357 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
358 }
359 if let Some(ref auth_conf) = configuration.basic_auth {
360 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
361 };
362 if let Some(ref token) = configuration.bearer_access_token {
363 req_builder = req_builder.bearer_auth(token.to_owned());
364 };
365 req_builder = req_builder.json(&p_body_service_account_create_input);
366
367 let req = req_builder.build()?;
368 let resp = configuration.client.execute(req).await?;
369
370 let status = resp.status();
371 let content_type = resp
372 .headers()
373 .get("content-type")
374 .and_then(|v| v.to_str().ok())
375 .unwrap_or("application/octet-stream");
376 let content_type = super::ContentType::from(content_type);
377
378 if !status.is_client_error() && !status.is_server_error() {
379 let content = resp.text().await?;
380 match content_type {
381 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
382 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserModel`"))),
383 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserModel`")))),
384 }
385 } else {
386 let content = resp.text().await?;
387 let entity: Option<PostServiceAccountError> = serde_json::from_str(&content).ok();
388 Err(Error::ResponseError(ResponseContent {
389 status,
390 content,
391 entity,
392 }))
393 }
394}
395
396pub async fn post_service_account_token(
397 configuration: &configuration::Configuration,
398 sa_identifier: &str,
399 service_account_create_input: models::ServiceAccountCreateInput,
400) -> Result<models::ServiceAccountTokenOutput, Error<PostServiceAccountTokenError>> {
401 let p_path_sa_identifier = sa_identifier;
403 let p_body_service_account_create_input = service_account_create_input;
404
405 let uri_str = format!(
406 "{}/service-accounts/{sa_identifier}/tokens",
407 configuration.base_path,
408 sa_identifier = crate::apis::urlencode(p_path_sa_identifier)
409 );
410 let mut req_builder = configuration
411 .client
412 .request(reqwest::Method::POST, &uri_str);
413
414 if let Some(ref apikey) = configuration.api_key {
415 let key = apikey.key.clone();
416 let value = match apikey.prefix {
417 Some(ref prefix) => format!("{} {}", prefix, key),
418 None => key,
419 };
420 req_builder = req_builder.query(&[("access_token", value)]);
421 }
422 if let Some(ref user_agent) = configuration.user_agent {
423 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
424 }
425 if let Some(ref auth_conf) = configuration.basic_auth {
426 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
427 };
428 if let Some(ref token) = configuration.bearer_access_token {
429 req_builder = req_builder.bearer_auth(token.to_owned());
430 };
431 req_builder = req_builder.json(&p_body_service_account_create_input);
432
433 let req = req_builder.build()?;
434 let resp = configuration.client.execute(req).await?;
435
436 let status = resp.status();
437 let content_type = resp
438 .headers()
439 .get("content-type")
440 .and_then(|v| v.to_str().ok())
441 .unwrap_or("application/octet-stream");
442 let content_type = super::ContentType::from(content_type);
443
444 if !status.is_client_error() && !status.is_server_error() {
445 let content = resp.text().await?;
446 match content_type {
447 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
448 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceAccountTokenOutput`"))),
449 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ServiceAccountTokenOutput`")))),
450 }
451 } else {
452 let content = resp.text().await?;
453 let entity: Option<PostServiceAccountTokenError> = serde_json::from_str(&content).ok();
454 Err(Error::ResponseError(ResponseContent {
455 status,
456 content,
457 entity,
458 }))
459 }
460}