1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct DownloadScanDataParams {
20 pub execution_id: i32,
22 pub x_request_id: Option<String>,
24 pub format: Option<String>
26}
27
28#[derive(Clone, Debug)]
30pub struct ExportScanDataParams {
31 pub x_scan_data_type: String,
33 pub criteria: models::ScanDataExportRequest,
35 pub x_request_id: Option<String>
37}
38
39#[derive(Clone, Debug)]
41pub struct GetScanDataExportExecutionParams {
42 pub execution_id: i32,
44 pub x_request_id: Option<String>
46}
47
48#[derive(Clone, Debug)]
50pub struct GetScanDataExportExecutionListParams {
51 pub x_request_id: Option<String>
53}
54
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum DownloadScanDataError {
60 Status401(models::Errors),
61 Status403(models::Errors),
62 Status404(models::Errors),
63 Status500(models::Errors),
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ExportScanDataError {
71 Status400(models::Errors),
72 Status401(models::Errors),
73 Status403(models::Errors),
74 Status404(models::Errors),
75 Status405(models::Errors),
76 Status409(models::Errors),
77 Status500(models::Errors),
78 UnknownValue(serde_json::Value),
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum GetScanDataExportExecutionError {
85 Status401(models::Errors),
86 Status403(models::Errors),
87 Status404(models::Errors),
88 Status500(models::Errors),
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum GetScanDataExportExecutionListError {
96 Status401(models::Errors),
97 Status403(models::Errors),
98 Status404(models::Errors),
99 Status500(models::Errors),
100 UnknownValue(serde_json::Value),
101}
102
103
104pub async fn download_scan_data(configuration: &configuration::Configuration, params: DownloadScanDataParams) -> Result<reqwest::Response, Error<DownloadScanDataError>> {
106
107 let uri_str = format!("{}/export/cve/download/{execution_id}", configuration.base_path, execution_id=params.execution_id);
108 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110 if let Some(ref param_value) = params.format {
111 req_builder = req_builder.query(&[("format", ¶m_value.to_string())]);
112 }
113 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116 if let Some(param_value) = params.x_request_id {
117 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
118 }
119 if let Some(ref auth_conf) = configuration.basic_auth {
120 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
121 };
122
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127
128 if !status.is_client_error() && !status.is_server_error() {
129 Ok(resp)
130 } else {
131 let content = resp.text().await?;
132 let entity: Option<DownloadScanDataError> = serde_json::from_str(&content).ok();
133 Err(Error::ResponseError(ResponseContent { status, content, entity }))
134 }
135}
136
137pub async fn export_scan_data(configuration: &configuration::Configuration, params: ExportScanDataParams) -> Result<models::ScanDataExportJob, Error<ExportScanDataError>> {
139
140 let uri_str = format!("{}/export/cve", configuration.base_path);
141 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
142
143 if let Some(ref user_agent) = configuration.user_agent {
144 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
145 }
146 if let Some(param_value) = params.x_request_id {
147 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
148 }
149 req_builder = req_builder.header("X-Scan-Data-Type", params.x_scan_data_type.to_string());
150 if let Some(ref auth_conf) = configuration.basic_auth {
151 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
152 };
153 req_builder = req_builder.json(¶ms.criteria);
154
155 let req = req_builder.build()?;
156 let resp = configuration.client.execute(req).await?;
157
158 let status = resp.status();
159 let content_type = resp
160 .headers()
161 .get("content-type")
162 .and_then(|v| v.to_str().ok())
163 .unwrap_or("application/octet-stream");
164 let content_type = super::ContentType::from(content_type);
165
166 if !status.is_client_error() && !status.is_server_error() {
167 let content = resp.text().await?;
168 match content_type {
169 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportJob`"))),
171 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::ScanDataExportJob`")))),
172 }
173 } else {
174 let content = resp.text().await?;
175 let entity: Option<ExportScanDataError> = serde_json::from_str(&content).ok();
176 Err(Error::ResponseError(ResponseContent { status, content, entity }))
177 }
178}
179
180pub async fn get_scan_data_export_execution(configuration: &configuration::Configuration, params: GetScanDataExportExecutionParams) -> Result<models::ScanDataExportExecution, Error<GetScanDataExportExecutionError>> {
182
183 let uri_str = format!("{}/export/cve/execution/{execution_id}", configuration.base_path, execution_id=params.execution_id);
184 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
185
186 if let Some(ref user_agent) = configuration.user_agent {
187 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188 }
189 if let Some(param_value) = params.x_request_id {
190 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
191 }
192 if let Some(ref auth_conf) = configuration.basic_auth {
193 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
194 };
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportExecution`"))),
212 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::ScanDataExportExecution`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<GetScanDataExportExecutionError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent { status, content, entity }))
218 }
219}
220
221pub async fn get_scan_data_export_execution_list(configuration: &configuration::Configuration, params: GetScanDataExportExecutionListParams) -> Result<models::ScanDataExportExecutionList, Error<GetScanDataExportExecutionListError>> {
223
224 let uri_str = format!("{}/export/cve/executions", configuration.base_path);
225 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
226
227 if let Some(ref user_agent) = configuration.user_agent {
228 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
229 }
230 if let Some(param_value) = params.x_request_id {
231 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
232 }
233 if let Some(ref auth_conf) = configuration.basic_auth {
234 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
235 };
236
237 let req = req_builder.build()?;
238 let resp = configuration.client.execute(req).await?;
239
240 let status = resp.status();
241 let content_type = resp
242 .headers()
243 .get("content-type")
244 .and_then(|v| v.to_str().ok())
245 .unwrap_or("application/octet-stream");
246 let content_type = super::ContentType::from(content_type);
247
248 if !status.is_client_error() && !status.is_server_error() {
249 let content = resp.text().await?;
250 match content_type {
251 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
252 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportExecutionList`"))),
253 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::ScanDataExportExecutionList`")))),
254 }
255 } else {
256 let content = resp.text().await?;
257 let entity: Option<GetScanDataExportExecutionListError> = serde_json::from_str(&content).ok();
258 Err(Error::ResponseError(ResponseContent { status, content, entity }))
259 }
260}
261