authentik_client/apis/
crypto_api.rs

1/*
2 * authentik
3 *
4 * Making authentication simple.
5 *
6 * The version of the OpenAPI document: 2025.8.3
7 * Contact: hello@goauthentik.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`crypto_certificatekeypairs_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CryptoCertificatekeypairsCreateError {
20    Status400(models::ValidationError),
21    Status403(models::GenericError),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`crypto_certificatekeypairs_destroy`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CryptoCertificatekeypairsDestroyError {
29    Status400(models::ValidationError),
30    Status403(models::GenericError),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`crypto_certificatekeypairs_generate_create`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum CryptoCertificatekeypairsGenerateCreateError {
38    Status400(),
39    Status403(models::GenericError),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`crypto_certificatekeypairs_list`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum CryptoCertificatekeypairsListError {
47    Status400(models::ValidationError),
48    Status403(models::GenericError),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`crypto_certificatekeypairs_partial_update`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum CryptoCertificatekeypairsPartialUpdateError {
56    Status400(models::ValidationError),
57    Status403(models::GenericError),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`crypto_certificatekeypairs_retrieve`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum CryptoCertificatekeypairsRetrieveError {
65    Status400(models::ValidationError),
66    Status403(models::GenericError),
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`crypto_certificatekeypairs_update`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum CryptoCertificatekeypairsUpdateError {
74    Status400(models::ValidationError),
75    Status403(models::GenericError),
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`crypto_certificatekeypairs_used_by_list`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum CryptoCertificatekeypairsUsedByListError {
83    Status400(models::ValidationError),
84    Status403(models::GenericError),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`crypto_certificatekeypairs_view_certificate_retrieve`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum CryptoCertificatekeypairsViewCertificateRetrieveError {
92    Status400(models::ValidationError),
93    Status403(models::GenericError),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`crypto_certificatekeypairs_view_private_key_retrieve`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum CryptoCertificatekeypairsViewPrivateKeyRetrieveError {
101    Status400(models::ValidationError),
102    Status403(models::GenericError),
103    UnknownValue(serde_json::Value),
104}
105
106/// CertificateKeyPair Viewset
107pub async fn crypto_certificatekeypairs_create(
108    configuration: &configuration::Configuration,
109    certificate_key_pair_request: models::CertificateKeyPairRequest,
110) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsCreateError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_body_certificate_key_pair_request = certificate_key_pair_request;
113
114    let uri_str = format!("{}/crypto/certificatekeypairs/", configuration.base_path);
115    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
116
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref token) = configuration.bearer_access_token {
121        req_builder = req_builder.bearer_auth(token.to_owned());
122    };
123    req_builder = req_builder.json(&p_body_certificate_key_pair_request);
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129    let content_type = resp
130        .headers()
131        .get("content-type")
132        .and_then(|v| v.to_str().ok())
133        .unwrap_or("application/octet-stream");
134    let content_type = super::ContentType::from(content_type);
135
136    if !status.is_client_error() && !status.is_server_error() {
137        let content = resp.text().await?;
138        match content_type {
139            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
140            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
141            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::CertificateKeyPair`")))),
142        }
143    } else {
144        let content = resp.text().await?;
145        let entity: Option<CryptoCertificatekeypairsCreateError> = serde_json::from_str(&content).ok();
146        Err(Error::ResponseError(ResponseContent {
147            status,
148            content,
149            entity,
150        }))
151    }
152}
153
154/// CertificateKeyPair Viewset
155pub async fn crypto_certificatekeypairs_destroy(
156    configuration: &configuration::Configuration,
157    kp_uuid: &str,
158) -> Result<(), Error<CryptoCertificatekeypairsDestroyError>> {
159    // add a prefix to parameters to efficiently prevent name collisions
160    let p_path_kp_uuid = kp_uuid;
161
162    let uri_str = format!(
163        "{}/crypto/certificatekeypairs/{kp_uuid}/",
164        configuration.base_path,
165        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
166    );
167    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref token) = configuration.bearer_access_token {
173        req_builder = req_builder.bearer_auth(token.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180
181    if !status.is_client_error() && !status.is_server_error() {
182        Ok(())
183    } else {
184        let content = resp.text().await?;
185        let entity: Option<CryptoCertificatekeypairsDestroyError> = serde_json::from_str(&content).ok();
186        Err(Error::ResponseError(ResponseContent {
187            status,
188            content,
189            entity,
190        }))
191    }
192}
193
194/// Generate a new, self-signed certificate-key pair
195pub async fn crypto_certificatekeypairs_generate_create(
196    configuration: &configuration::Configuration,
197    certificate_generation_request: models::CertificateGenerationRequest,
198) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsGenerateCreateError>> {
199    // add a prefix to parameters to efficiently prevent name collisions
200    let p_body_certificate_generation_request = certificate_generation_request;
201
202    let uri_str = format!("{}/crypto/certificatekeypairs/generate/", configuration.base_path);
203    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
204
205    if let Some(ref user_agent) = configuration.user_agent {
206        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207    }
208    if let Some(ref token) = configuration.bearer_access_token {
209        req_builder = req_builder.bearer_auth(token.to_owned());
210    };
211    req_builder = req_builder.json(&p_body_certificate_generation_request);
212
213    let req = req_builder.build()?;
214    let resp = configuration.client.execute(req).await?;
215
216    let status = resp.status();
217    let content_type = resp
218        .headers()
219        .get("content-type")
220        .and_then(|v| v.to_str().ok())
221        .unwrap_or("application/octet-stream");
222    let content_type = super::ContentType::from(content_type);
223
224    if !status.is_client_error() && !status.is_server_error() {
225        let content = resp.text().await?;
226        match content_type {
227            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
228            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
229            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::CertificateKeyPair`")))),
230        }
231    } else {
232        let content = resp.text().await?;
233        let entity: Option<CryptoCertificatekeypairsGenerateCreateError> = serde_json::from_str(&content).ok();
234        Err(Error::ResponseError(ResponseContent {
235            status,
236            content,
237            entity,
238        }))
239    }
240}
241
242/// CertificateKeyPair Viewset
243pub async fn crypto_certificatekeypairs_list(
244    configuration: &configuration::Configuration,
245    has_key: Option<bool>,
246    include_details: Option<bool>,
247    managed: Option<&str>,
248    name: Option<&str>,
249    ordering: Option<&str>,
250    page: Option<i32>,
251    page_size: Option<i32>,
252    search: Option<&str>,
253) -> Result<models::PaginatedCertificateKeyPairList, Error<CryptoCertificatekeypairsListError>> {
254    // add a prefix to parameters to efficiently prevent name collisions
255    let p_query_has_key = has_key;
256    let p_query_include_details = include_details;
257    let p_query_managed = managed;
258    let p_query_name = name;
259    let p_query_ordering = ordering;
260    let p_query_page = page;
261    let p_query_page_size = page_size;
262    let p_query_search = search;
263
264    let uri_str = format!("{}/crypto/certificatekeypairs/", configuration.base_path);
265    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
266
267    if let Some(ref param_value) = p_query_has_key {
268        req_builder = req_builder.query(&[("has_key", &param_value.to_string())]);
269    }
270    if let Some(ref param_value) = p_query_include_details {
271        req_builder = req_builder.query(&[("include_details", &param_value.to_string())]);
272    }
273    if let Some(ref param_value) = p_query_managed {
274        req_builder = req_builder.query(&[("managed", &param_value.to_string())]);
275    }
276    if let Some(ref param_value) = p_query_name {
277        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
278    }
279    if let Some(ref param_value) = p_query_ordering {
280        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
281    }
282    if let Some(ref param_value) = p_query_page {
283        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
284    }
285    if let Some(ref param_value) = p_query_page_size {
286        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
287    }
288    if let Some(ref param_value) = p_query_search {
289        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
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 token) = configuration.bearer_access_token {
295        req_builder = req_builder.bearer_auth(token.to_owned());
296    };
297
298    let req = req_builder.build()?;
299    let resp = configuration.client.execute(req).await?;
300
301    let status = resp.status();
302    let content_type = resp
303        .headers()
304        .get("content-type")
305        .and_then(|v| v.to_str().ok())
306        .unwrap_or("application/octet-stream");
307    let content_type = super::ContentType::from(content_type);
308
309    if !status.is_client_error() && !status.is_server_error() {
310        let content = resp.text().await?;
311        match content_type {
312            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
313            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedCertificateKeyPairList`"))),
314            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::PaginatedCertificateKeyPairList`")))),
315        }
316    } else {
317        let content = resp.text().await?;
318        let entity: Option<CryptoCertificatekeypairsListError> = serde_json::from_str(&content).ok();
319        Err(Error::ResponseError(ResponseContent {
320            status,
321            content,
322            entity,
323        }))
324    }
325}
326
327/// CertificateKeyPair Viewset
328pub async fn crypto_certificatekeypairs_partial_update(
329    configuration: &configuration::Configuration,
330    kp_uuid: &str,
331    patched_certificate_key_pair_request: Option<models::PatchedCertificateKeyPairRequest>,
332) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsPartialUpdateError>> {
333    // add a prefix to parameters to efficiently prevent name collisions
334    let p_path_kp_uuid = kp_uuid;
335    let p_body_patched_certificate_key_pair_request = patched_certificate_key_pair_request;
336
337    let uri_str = format!(
338        "{}/crypto/certificatekeypairs/{kp_uuid}/",
339        configuration.base_path,
340        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
341    );
342    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
343
344    if let Some(ref user_agent) = configuration.user_agent {
345        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
346    }
347    if let Some(ref token) = configuration.bearer_access_token {
348        req_builder = req_builder.bearer_auth(token.to_owned());
349    };
350    req_builder = req_builder.json(&p_body_patched_certificate_key_pair_request);
351
352    let req = req_builder.build()?;
353    let resp = configuration.client.execute(req).await?;
354
355    let status = resp.status();
356    let content_type = resp
357        .headers()
358        .get("content-type")
359        .and_then(|v| v.to_str().ok())
360        .unwrap_or("application/octet-stream");
361    let content_type = super::ContentType::from(content_type);
362
363    if !status.is_client_error() && !status.is_server_error() {
364        let content = resp.text().await?;
365        match content_type {
366            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
367            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
368            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::CertificateKeyPair`")))),
369        }
370    } else {
371        let content = resp.text().await?;
372        let entity: Option<CryptoCertificatekeypairsPartialUpdateError> = serde_json::from_str(&content).ok();
373        Err(Error::ResponseError(ResponseContent {
374            status,
375            content,
376            entity,
377        }))
378    }
379}
380
381/// CertificateKeyPair Viewset
382pub async fn crypto_certificatekeypairs_retrieve(
383    configuration: &configuration::Configuration,
384    kp_uuid: &str,
385) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsRetrieveError>> {
386    // add a prefix to parameters to efficiently prevent name collisions
387    let p_path_kp_uuid = kp_uuid;
388
389    let uri_str = format!(
390        "{}/crypto/certificatekeypairs/{kp_uuid}/",
391        configuration.base_path,
392        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
393    );
394    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
395
396    if let Some(ref user_agent) = configuration.user_agent {
397        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
398    }
399    if let Some(ref token) = configuration.bearer_access_token {
400        req_builder = req_builder.bearer_auth(token.to_owned());
401    };
402
403    let req = req_builder.build()?;
404    let resp = configuration.client.execute(req).await?;
405
406    let status = resp.status();
407    let content_type = resp
408        .headers()
409        .get("content-type")
410        .and_then(|v| v.to_str().ok())
411        .unwrap_or("application/octet-stream");
412    let content_type = super::ContentType::from(content_type);
413
414    if !status.is_client_error() && !status.is_server_error() {
415        let content = resp.text().await?;
416        match content_type {
417            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
418            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
419            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::CertificateKeyPair`")))),
420        }
421    } else {
422        let content = resp.text().await?;
423        let entity: Option<CryptoCertificatekeypairsRetrieveError> = serde_json::from_str(&content).ok();
424        Err(Error::ResponseError(ResponseContent {
425            status,
426            content,
427            entity,
428        }))
429    }
430}
431
432/// CertificateKeyPair Viewset
433pub async fn crypto_certificatekeypairs_update(
434    configuration: &configuration::Configuration,
435    kp_uuid: &str,
436    certificate_key_pair_request: models::CertificateKeyPairRequest,
437) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsUpdateError>> {
438    // add a prefix to parameters to efficiently prevent name collisions
439    let p_path_kp_uuid = kp_uuid;
440    let p_body_certificate_key_pair_request = certificate_key_pair_request;
441
442    let uri_str = format!(
443        "{}/crypto/certificatekeypairs/{kp_uuid}/",
444        configuration.base_path,
445        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
446    );
447    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
448
449    if let Some(ref user_agent) = configuration.user_agent {
450        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
451    }
452    if let Some(ref token) = configuration.bearer_access_token {
453        req_builder = req_builder.bearer_auth(token.to_owned());
454    };
455    req_builder = req_builder.json(&p_body_certificate_key_pair_request);
456
457    let req = req_builder.build()?;
458    let resp = configuration.client.execute(req).await?;
459
460    let status = resp.status();
461    let content_type = resp
462        .headers()
463        .get("content-type")
464        .and_then(|v| v.to_str().ok())
465        .unwrap_or("application/octet-stream");
466    let content_type = super::ContentType::from(content_type);
467
468    if !status.is_client_error() && !status.is_server_error() {
469        let content = resp.text().await?;
470        match content_type {
471            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
472            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
473            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::CertificateKeyPair`")))),
474        }
475    } else {
476        let content = resp.text().await?;
477        let entity: Option<CryptoCertificatekeypairsUpdateError> = serde_json::from_str(&content).ok();
478        Err(Error::ResponseError(ResponseContent {
479            status,
480            content,
481            entity,
482        }))
483    }
484}
485
486/// Get a list of all objects that use this object
487pub async fn crypto_certificatekeypairs_used_by_list(
488    configuration: &configuration::Configuration,
489    kp_uuid: &str,
490) -> Result<Vec<models::UsedBy>, Error<CryptoCertificatekeypairsUsedByListError>> {
491    // add a prefix to parameters to efficiently prevent name collisions
492    let p_path_kp_uuid = kp_uuid;
493
494    let uri_str = format!(
495        "{}/crypto/certificatekeypairs/{kp_uuid}/used_by/",
496        configuration.base_path,
497        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
498    );
499    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
500
501    if let Some(ref user_agent) = configuration.user_agent {
502        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
503    }
504    if let Some(ref token) = configuration.bearer_access_token {
505        req_builder = req_builder.bearer_auth(token.to_owned());
506    };
507
508    let req = req_builder.build()?;
509    let resp = configuration.client.execute(req).await?;
510
511    let status = resp.status();
512    let content_type = resp
513        .headers()
514        .get("content-type")
515        .and_then(|v| v.to_str().ok())
516        .unwrap_or("application/octet-stream");
517    let content_type = super::ContentType::from(content_type);
518
519    if !status.is_client_error() && !status.is_server_error() {
520        let content = resp.text().await?;
521        match content_type {
522            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
523            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::UsedBy&gt;`"))),
524            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&lt;models::UsedBy&gt;`")))),
525        }
526    } else {
527        let content = resp.text().await?;
528        let entity: Option<CryptoCertificatekeypairsUsedByListError> = serde_json::from_str(&content).ok();
529        Err(Error::ResponseError(ResponseContent {
530            status,
531            content,
532            entity,
533        }))
534    }
535}
536
537/// Return certificate-key pairs certificate and log access
538pub async fn crypto_certificatekeypairs_view_certificate_retrieve(
539    configuration: &configuration::Configuration,
540    kp_uuid: &str,
541    download: Option<bool>,
542) -> Result<models::CertificateData, Error<CryptoCertificatekeypairsViewCertificateRetrieveError>> {
543    // add a prefix to parameters to efficiently prevent name collisions
544    let p_path_kp_uuid = kp_uuid;
545    let p_query_download = download;
546
547    let uri_str = format!(
548        "{}/crypto/certificatekeypairs/{kp_uuid}/view_certificate/",
549        configuration.base_path,
550        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
551    );
552    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
553
554    if let Some(ref param_value) = p_query_download {
555        req_builder = req_builder.query(&[("download", &param_value.to_string())]);
556    }
557    if let Some(ref user_agent) = configuration.user_agent {
558        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
559    }
560    if let Some(ref token) = configuration.bearer_access_token {
561        req_builder = req_builder.bearer_auth(token.to_owned());
562    };
563
564    let req = req_builder.build()?;
565    let resp = configuration.client.execute(req).await?;
566
567    let status = resp.status();
568    let content_type = resp
569        .headers()
570        .get("content-type")
571        .and_then(|v| v.to_str().ok())
572        .unwrap_or("application/octet-stream");
573    let content_type = super::ContentType::from(content_type);
574
575    if !status.is_client_error() && !status.is_server_error() {
576        let content = resp.text().await?;
577        match content_type {
578            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
579            ContentType::Text => {
580                return Err(Error::from(serde_json::Error::custom(
581                    "Received `text/plain` content type response that cannot be converted to `models::CertificateData`",
582                )))
583            }
584            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!(
585                "Received `{unknown_type}` content type response that cannot be converted to `models::CertificateData`"
586            )))),
587        }
588    } else {
589        let content = resp.text().await?;
590        let entity: Option<CryptoCertificatekeypairsViewCertificateRetrieveError> = serde_json::from_str(&content).ok();
591        Err(Error::ResponseError(ResponseContent {
592            status,
593            content,
594            entity,
595        }))
596    }
597}
598
599/// Return certificate-key pairs private key and log access
600pub async fn crypto_certificatekeypairs_view_private_key_retrieve(
601    configuration: &configuration::Configuration,
602    kp_uuid: &str,
603    download: Option<bool>,
604) -> Result<models::CertificateData, Error<CryptoCertificatekeypairsViewPrivateKeyRetrieveError>> {
605    // add a prefix to parameters to efficiently prevent name collisions
606    let p_path_kp_uuid = kp_uuid;
607    let p_query_download = download;
608
609    let uri_str = format!(
610        "{}/crypto/certificatekeypairs/{kp_uuid}/view_private_key/",
611        configuration.base_path,
612        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
613    );
614    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
615
616    if let Some(ref param_value) = p_query_download {
617        req_builder = req_builder.query(&[("download", &param_value.to_string())]);
618    }
619    if let Some(ref user_agent) = configuration.user_agent {
620        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
621    }
622    if let Some(ref token) = configuration.bearer_access_token {
623        req_builder = req_builder.bearer_auth(token.to_owned());
624    };
625
626    let req = req_builder.build()?;
627    let resp = configuration.client.execute(req).await?;
628
629    let status = resp.status();
630    let content_type = resp
631        .headers()
632        .get("content-type")
633        .and_then(|v| v.to_str().ok())
634        .unwrap_or("application/octet-stream");
635    let content_type = super::ContentType::from(content_type);
636
637    if !status.is_client_error() && !status.is_server_error() {
638        let content = resp.text().await?;
639        match content_type {
640            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
641            ContentType::Text => {
642                return Err(Error::from(serde_json::Error::custom(
643                    "Received `text/plain` content type response that cannot be converted to `models::CertificateData`",
644                )))
645            }
646            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!(
647                "Received `{unknown_type}` content type response that cannot be converted to `models::CertificateData`"
648            )))),
649        }
650    } else {
651        let content = resp.text().await?;
652        let entity: Option<CryptoCertificatekeypairsViewPrivateKeyRetrieveError> = serde_json::from_str(&content).ok();
653        Err(Error::ResponseError(ResponseContent {
654            status,
655            content,
656            entity,
657        }))
658    }
659}