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