authentik_client/apis/
reports_api.rs

1/*
2 * authentik
3 *
4 * Making authentication simple.
5 *
6 * The version of the OpenAPI document: 2025.12.1
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 [`reports_exports_destroy`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ReportsExportsDestroyError {
20    Status400(models::ValidationError),
21    Status403(models::GenericError),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`reports_exports_list`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ReportsExportsListError {
29    Status400(models::ValidationError),
30    Status403(models::GenericError),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`reports_exports_retrieve`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ReportsExportsRetrieveError {
38    Status400(models::ValidationError),
39    Status403(models::GenericError),
40    UnknownValue(serde_json::Value),
41}
42
43pub async fn reports_exports_destroy(
44    configuration: &configuration::Configuration,
45    id: &str,
46) -> Result<(), Error<ReportsExportsDestroyError>> {
47    // add a prefix to parameters to efficiently prevent name collisions
48    let p_path_id = id;
49
50    let uri_str = format!(
51        "{}/reports/exports/{id}/",
52        configuration.base_path,
53        id = crate::apis::urlencode(p_path_id)
54    );
55    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
56
57    if let Some(ref user_agent) = configuration.user_agent {
58        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
59    }
60    if let Some(ref token) = configuration.bearer_access_token {
61        req_builder = req_builder.bearer_auth(token.to_owned());
62    };
63
64    let req = req_builder.build()?;
65    let resp = configuration.client.execute(req).await?;
66
67    let status = resp.status();
68
69    if !status.is_client_error() && !status.is_server_error() {
70        Ok(())
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<ReportsExportsDestroyError> = serde_json::from_str(&content).ok();
74        Err(Error::ResponseError(ResponseContent {
75            status,
76            content,
77            entity,
78        }))
79    }
80}
81
82pub async fn reports_exports_list(
83    configuration: &configuration::Configuration,
84    ordering: Option<&str>,
85    page: Option<i32>,
86    page_size: Option<i32>,
87    search: Option<&str>,
88) -> Result<models::PaginatedDataExportList, Error<ReportsExportsListError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_query_ordering = ordering;
91    let p_query_page = page;
92    let p_query_page_size = page_size;
93    let p_query_search = search;
94
95    let uri_str = format!("{}/reports/exports/", configuration.base_path);
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref param_value) = p_query_ordering {
99        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
100    }
101    if let Some(ref param_value) = p_query_page {
102        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
103    }
104    if let Some(ref param_value) = p_query_page_size {
105        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
106    }
107    if let Some(ref param_value) = p_query_search {
108        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
109    }
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDataExportList`"))),
133            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::PaginatedDataExportList`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<ReportsExportsListError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent {
139            status,
140            content,
141            entity,
142        }))
143    }
144}
145
146pub async fn reports_exports_retrieve(
147    configuration: &configuration::Configuration,
148    id: &str,
149) -> Result<models::DataExport, Error<ReportsExportsRetrieveError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_path_id = id;
152
153    let uri_str = format!(
154        "{}/reports/exports/{id}/",
155        configuration.base_path,
156        id = crate::apis::urlencode(p_path_id)
157    );
158    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
159
160    if let Some(ref user_agent) = configuration.user_agent {
161        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
162    }
163    if let Some(ref token) = configuration.bearer_access_token {
164        req_builder = req_builder.bearer_auth(token.to_owned());
165    };
166
167    let req = req_builder.build()?;
168    let resp = configuration.client.execute(req).await?;
169
170    let status = resp.status();
171    let content_type = resp
172        .headers()
173        .get("content-type")
174        .and_then(|v| v.to_str().ok())
175        .unwrap_or("application/octet-stream");
176    let content_type = super::ContentType::from(content_type);
177
178    if !status.is_client_error() && !status.is_server_error() {
179        let content = resp.text().await?;
180        match content_type {
181            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
182            ContentType::Text => {
183                return Err(Error::from(serde_json::Error::custom(
184                    "Received `text/plain` content type response that cannot be converted to `models::DataExport`",
185                )))
186            }
187            ContentType::Unsupported(unknown_type) => {
188                return Err(Error::from(serde_json::Error::custom(format!(
189                    "Received `{unknown_type}` content type response that cannot be converted to `models::DataExport`"
190                ))))
191            }
192        }
193    } else {
194        let content = resp.text().await?;
195        let entity: Option<ReportsExportsRetrieveError> = serde_json::from_str(&content).ok();
196        Err(Error::ResponseError(ResponseContent {
197            status,
198            content,
199            entity,
200        }))
201    }
202}