use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug)]
pub struct DownloadScanDataParams {
pub execution_id: i32,
pub x_request_id: Option<String>,
pub format: Option<String>
}
#[derive(Clone, Debug)]
pub struct ExportScanDataParams {
pub x_scan_data_type: String,
pub criteria: models::ScanDataExportRequest,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetScanDataExportExecutionParams {
pub execution_id: i32,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetScanDataExportExecutionListParams {
pub x_request_id: Option<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DownloadScanDataError {
Status401(models::Errors),
Status403(models::Errors),
Status404(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ExportScanDataError {
Status400(models::Errors),
Status401(models::Errors),
Status403(models::Errors),
Status404(models::Errors),
Status405(models::Errors),
Status409(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetScanDataExportExecutionError {
Status401(models::Errors),
Status403(models::Errors),
Status404(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetScanDataExportExecutionListError {
Status401(models::Errors),
Status403(models::Errors),
Status404(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
pub async fn download_scan_data(configuration: &configuration::Configuration, params: DownloadScanDataParams) -> Result<reqwest::Response, Error<DownloadScanDataError>> {
let uri_str = format!("{}/export/cve/download/{execution_id}", configuration.base_path, execution_id=params.execution_id);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.format {
req_builder = req_builder.query(&[("format", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = params.x_request_id {
req_builder = req_builder.header("X-Request-Id", param_value.to_string());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(resp)
} else {
let content = resp.text().await?;
let entity: Option<DownloadScanDataError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn export_scan_data(configuration: &configuration::Configuration, params: ExportScanDataParams) -> Result<models::ScanDataExportJob, Error<ExportScanDataError>> {
let uri_str = format!("{}/export/cve", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = params.x_request_id {
req_builder = req_builder.header("X-Request-Id", param_value.to_string());
}
req_builder = req_builder.header("X-Scan-Data-Type", params.x_scan_data_type.to_string());
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(¶ms.criteria);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportJob`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ExportScanDataError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_scan_data_export_execution(configuration: &configuration::Configuration, params: GetScanDataExportExecutionParams) -> Result<models::ScanDataExportExecution, Error<GetScanDataExportExecutionError>> {
let uri_str = format!("{}/export/cve/execution/{execution_id}", configuration.base_path, execution_id=params.execution_id);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = params.x_request_id {
req_builder = req_builder.header("X-Request-Id", param_value.to_string());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportExecution`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScanDataExportExecutionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_scan_data_export_execution_list(configuration: &configuration::Configuration, params: GetScanDataExportExecutionListParams) -> Result<models::ScanDataExportExecutionList, Error<GetScanDataExportExecutionListError>> {
let uri_str = format!("{}/export/cve/executions", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = params.x_request_id {
req_builder = req_builder.header("X-Request-Id", param_value.to_string());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScanDataExportExecutionList`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScanDataExportExecutionListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}