Skip to main content

authentik_client/apis/
crypto_api.rs

1/*
2 * authentik
3 *
4 * Making authentication simple.
5 *
6 * The version of the OpenAPI document: 2026.2.0
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    key_type: Option<Vec<String>>,
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_key_type = key_type;
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_key_type {
271        req_builder = match "multi" {
272            "multi" => req_builder.query(
273                &param_value
274                    .into_iter()
275                    .map(|p| ("key_type".to_owned(), p.to_string()))
276                    .collect::<Vec<(std::string::String, std::string::String)>>(),
277            ),
278            _ => req_builder.query(&[(
279                "key_type",
280                &param_value
281                    .into_iter()
282                    .map(|p| p.to_string())
283                    .collect::<Vec<String>>()
284                    .join(",")
285                    .to_string(),
286            )]),
287        };
288    }
289    if let Some(ref param_value) = p_query_managed {
290        req_builder = req_builder.query(&[("managed", &param_value.to_string())]);
291    }
292    if let Some(ref param_value) = p_query_name {
293        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
294    }
295    if let Some(ref param_value) = p_query_ordering {
296        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
297    }
298    if let Some(ref param_value) = p_query_page {
299        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
300    }
301    if let Some(ref param_value) = p_query_page_size {
302        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
303    }
304    if let Some(ref param_value) = p_query_search {
305        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
306    }
307    if let Some(ref user_agent) = configuration.user_agent {
308        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
309    }
310    if let Some(ref token) = configuration.bearer_access_token {
311        req_builder = req_builder.bearer_auth(token.to_owned());
312    };
313
314    let req = req_builder.build()?;
315    let resp = configuration.client.execute(req).await?;
316
317    let status = resp.status();
318    let content_type = resp
319        .headers()
320        .get("content-type")
321        .and_then(|v| v.to_str().ok())
322        .unwrap_or("application/octet-stream");
323    let content_type = super::ContentType::from(content_type);
324
325    if !status.is_client_error() && !status.is_server_error() {
326        let content = resp.text().await?;
327        match content_type {
328            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedCertificateKeyPairList`"))),
330            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`")))),
331        }
332    } else {
333        let content = resp.text().await?;
334        let entity: Option<CryptoCertificatekeypairsListError> = serde_json::from_str(&content).ok();
335        Err(Error::ResponseError(ResponseContent {
336            status,
337            content,
338            entity,
339        }))
340    }
341}
342
343/// CertificateKeyPair Viewset
344pub async fn crypto_certificatekeypairs_partial_update(
345    configuration: &configuration::Configuration,
346    kp_uuid: &str,
347    patched_certificate_key_pair_request: Option<models::PatchedCertificateKeyPairRequest>,
348) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsPartialUpdateError>> {
349    // add a prefix to parameters to efficiently prevent name collisions
350    let p_path_kp_uuid = kp_uuid;
351    let p_body_patched_certificate_key_pair_request = patched_certificate_key_pair_request;
352
353    let uri_str = format!(
354        "{}/crypto/certificatekeypairs/{kp_uuid}/",
355        configuration.base_path,
356        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
357    );
358    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
359
360    if let Some(ref user_agent) = configuration.user_agent {
361        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
362    }
363    if let Some(ref token) = configuration.bearer_access_token {
364        req_builder = req_builder.bearer_auth(token.to_owned());
365    };
366    req_builder = req_builder.json(&p_body_patched_certificate_key_pair_request);
367
368    let req = req_builder.build()?;
369    let resp = configuration.client.execute(req).await?;
370
371    let status = resp.status();
372    let content_type = resp
373        .headers()
374        .get("content-type")
375        .and_then(|v| v.to_str().ok())
376        .unwrap_or("application/octet-stream");
377    let content_type = super::ContentType::from(content_type);
378
379    if !status.is_client_error() && !status.is_server_error() {
380        let content = resp.text().await?;
381        match content_type {
382            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
383            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
384            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`")))),
385        }
386    } else {
387        let content = resp.text().await?;
388        let entity: Option<CryptoCertificatekeypairsPartialUpdateError> = serde_json::from_str(&content).ok();
389        Err(Error::ResponseError(ResponseContent {
390            status,
391            content,
392            entity,
393        }))
394    }
395}
396
397/// CertificateKeyPair Viewset
398pub async fn crypto_certificatekeypairs_retrieve(
399    configuration: &configuration::Configuration,
400    kp_uuid: &str,
401) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsRetrieveError>> {
402    // add a prefix to parameters to efficiently prevent name collisions
403    let p_path_kp_uuid = kp_uuid;
404
405    let uri_str = format!(
406        "{}/crypto/certificatekeypairs/{kp_uuid}/",
407        configuration.base_path,
408        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
409    );
410    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
411
412    if let Some(ref user_agent) = configuration.user_agent {
413        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
414    }
415    if let Some(ref token) = configuration.bearer_access_token {
416        req_builder = req_builder.bearer_auth(token.to_owned());
417    };
418
419    let req = req_builder.build()?;
420    let resp = configuration.client.execute(req).await?;
421
422    let status = resp.status();
423    let content_type = resp
424        .headers()
425        .get("content-type")
426        .and_then(|v| v.to_str().ok())
427        .unwrap_or("application/octet-stream");
428    let content_type = super::ContentType::from(content_type);
429
430    if !status.is_client_error() && !status.is_server_error() {
431        let content = resp.text().await?;
432        match content_type {
433            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
434            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
435            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`")))),
436        }
437    } else {
438        let content = resp.text().await?;
439        let entity: Option<CryptoCertificatekeypairsRetrieveError> = serde_json::from_str(&content).ok();
440        Err(Error::ResponseError(ResponseContent {
441            status,
442            content,
443            entity,
444        }))
445    }
446}
447
448/// CertificateKeyPair Viewset
449pub async fn crypto_certificatekeypairs_update(
450    configuration: &configuration::Configuration,
451    kp_uuid: &str,
452    certificate_key_pair_request: models::CertificateKeyPairRequest,
453) -> Result<models::CertificateKeyPair, Error<CryptoCertificatekeypairsUpdateError>> {
454    // add a prefix to parameters to efficiently prevent name collisions
455    let p_path_kp_uuid = kp_uuid;
456    let p_body_certificate_key_pair_request = certificate_key_pair_request;
457
458    let uri_str = format!(
459        "{}/crypto/certificatekeypairs/{kp_uuid}/",
460        configuration.base_path,
461        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
462    );
463    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
464
465    if let Some(ref user_agent) = configuration.user_agent {
466        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
467    }
468    if let Some(ref token) = configuration.bearer_access_token {
469        req_builder = req_builder.bearer_auth(token.to_owned());
470    };
471    req_builder = req_builder.json(&p_body_certificate_key_pair_request);
472
473    let req = req_builder.build()?;
474    let resp = configuration.client.execute(req).await?;
475
476    let status = resp.status();
477    let content_type = resp
478        .headers()
479        .get("content-type")
480        .and_then(|v| v.to_str().ok())
481        .unwrap_or("application/octet-stream");
482    let content_type = super::ContentType::from(content_type);
483
484    if !status.is_client_error() && !status.is_server_error() {
485        let content = resp.text().await?;
486        match content_type {
487            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
488            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CertificateKeyPair`"))),
489            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`")))),
490        }
491    } else {
492        let content = resp.text().await?;
493        let entity: Option<CryptoCertificatekeypairsUpdateError> = serde_json::from_str(&content).ok();
494        Err(Error::ResponseError(ResponseContent {
495            status,
496            content,
497            entity,
498        }))
499    }
500}
501
502/// Get a list of all objects that use this object
503pub async fn crypto_certificatekeypairs_used_by_list(
504    configuration: &configuration::Configuration,
505    kp_uuid: &str,
506) -> Result<Vec<models::UsedBy>, Error<CryptoCertificatekeypairsUsedByListError>> {
507    // add a prefix to parameters to efficiently prevent name collisions
508    let p_path_kp_uuid = kp_uuid;
509
510    let uri_str = format!(
511        "{}/crypto/certificatekeypairs/{kp_uuid}/used_by/",
512        configuration.base_path,
513        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
514    );
515    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
516
517    if let Some(ref user_agent) = configuration.user_agent {
518        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
519    }
520    if let Some(ref token) = configuration.bearer_access_token {
521        req_builder = req_builder.bearer_auth(token.to_owned());
522    };
523
524    let req = req_builder.build()?;
525    let resp = configuration.client.execute(req).await?;
526
527    let status = resp.status();
528    let content_type = resp
529        .headers()
530        .get("content-type")
531        .and_then(|v| v.to_str().ok())
532        .unwrap_or("application/octet-stream");
533    let content_type = super::ContentType::from(content_type);
534
535    if !status.is_client_error() && !status.is_server_error() {
536        let content = resp.text().await?;
537        match content_type {
538            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
539            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;`"))),
540            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;`")))),
541        }
542    } else {
543        let content = resp.text().await?;
544        let entity: Option<CryptoCertificatekeypairsUsedByListError> = serde_json::from_str(&content).ok();
545        Err(Error::ResponseError(ResponseContent {
546            status,
547            content,
548            entity,
549        }))
550    }
551}
552
553/// Return certificate-key pairs certificate and log access
554pub async fn crypto_certificatekeypairs_view_certificate_retrieve(
555    configuration: &configuration::Configuration,
556    kp_uuid: &str,
557    download: Option<bool>,
558) -> Result<models::CertificateData, Error<CryptoCertificatekeypairsViewCertificateRetrieveError>> {
559    // add a prefix to parameters to efficiently prevent name collisions
560    let p_path_kp_uuid = kp_uuid;
561    let p_query_download = download;
562
563    let uri_str = format!(
564        "{}/crypto/certificatekeypairs/{kp_uuid}/view_certificate/",
565        configuration.base_path,
566        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
567    );
568    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
569
570    if let Some(ref param_value) = p_query_download {
571        req_builder = req_builder.query(&[("download", &param_value.to_string())]);
572    }
573    if let Some(ref user_agent) = configuration.user_agent {
574        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
575    }
576    if let Some(ref token) = configuration.bearer_access_token {
577        req_builder = req_builder.bearer_auth(token.to_owned());
578    };
579
580    let req = req_builder.build()?;
581    let resp = configuration.client.execute(req).await?;
582
583    let status = resp.status();
584    let content_type = resp
585        .headers()
586        .get("content-type")
587        .and_then(|v| v.to_str().ok())
588        .unwrap_or("application/octet-stream");
589    let content_type = super::ContentType::from(content_type);
590
591    if !status.is_client_error() && !status.is_server_error() {
592        let content = resp.text().await?;
593        match content_type {
594            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
595            ContentType::Text => {
596                return Err(Error::from(serde_json::Error::custom(
597                    "Received `text/plain` content type response that cannot be converted to `models::CertificateData`",
598                )))
599            }
600            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!(
601                "Received `{unknown_type}` content type response that cannot be converted to `models::CertificateData`"
602            )))),
603        }
604    } else {
605        let content = resp.text().await?;
606        let entity: Option<CryptoCertificatekeypairsViewCertificateRetrieveError> = serde_json::from_str(&content).ok();
607        Err(Error::ResponseError(ResponseContent {
608            status,
609            content,
610            entity,
611        }))
612    }
613}
614
615/// Return certificate-key pairs private key and log access
616pub async fn crypto_certificatekeypairs_view_private_key_retrieve(
617    configuration: &configuration::Configuration,
618    kp_uuid: &str,
619    download: Option<bool>,
620) -> Result<models::CertificateData, Error<CryptoCertificatekeypairsViewPrivateKeyRetrieveError>> {
621    // add a prefix to parameters to efficiently prevent name collisions
622    let p_path_kp_uuid = kp_uuid;
623    let p_query_download = download;
624
625    let uri_str = format!(
626        "{}/crypto/certificatekeypairs/{kp_uuid}/view_private_key/",
627        configuration.base_path,
628        kp_uuid = crate::apis::urlencode(p_path_kp_uuid)
629    );
630    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
631
632    if let Some(ref param_value) = p_query_download {
633        req_builder = req_builder.query(&[("download", &param_value.to_string())]);
634    }
635    if let Some(ref user_agent) = configuration.user_agent {
636        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
637    }
638    if let Some(ref token) = configuration.bearer_access_token {
639        req_builder = req_builder.bearer_auth(token.to_owned());
640    };
641
642    let req = req_builder.build()?;
643    let resp = configuration.client.execute(req).await?;
644
645    let status = resp.status();
646    let content_type = resp
647        .headers()
648        .get("content-type")
649        .and_then(|v| v.to_str().ok())
650        .unwrap_or("application/octet-stream");
651    let content_type = super::ContentType::from(content_type);
652
653    if !status.is_client_error() && !status.is_server_error() {
654        let content = resp.text().await?;
655        match content_type {
656            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
657            ContentType::Text => {
658                return Err(Error::from(serde_json::Error::custom(
659                    "Received `text/plain` content type response that cannot be converted to `models::CertificateData`",
660                )))
661            }
662            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!(
663                "Received `{unknown_type}` content type response that cannot be converted to `models::CertificateData`"
664            )))),
665        }
666    } else {
667        let content = resp.text().await?;
668        let entity: Option<CryptoCertificatekeypairsViewPrivateKeyRetrieveError> = serde_json::from_str(&content).ok();
669        Err(Error::ResponseError(ResponseContent {
670            status,
671            content,
672            entity,
673        }))
674    }
675}