use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug)]
pub struct CreateScanAllScheduleParams {
pub schedule: models::Schedule,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetLatestScanAllMetricsParams {
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetLatestScheduledScanAllMetricsParams {
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetScanAllScheduleParams {
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct StopScanAllParams {
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct UpdateScanAllScheduleParams {
pub schedule: models::Schedule,
pub x_request_id: Option<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateScanAllScheduleError {
Status400(models::Errors),
Status401(models::Errors),
Status403(models::Errors),
Status409(models::Errors),
Status412(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLatestScanAllMetricsError {
Status401(models::Errors),
Status403(models::Errors),
Status412(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLatestScheduledScanAllMetricsError {
Status401(models::Errors),
Status403(models::Errors),
Status412(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetScanAllScheduleError {
Status401(models::Errors),
Status403(models::Errors),
Status412(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StopScanAllError {
Status400(models::Errors),
Status401(models::Errors),
Status403(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateScanAllScheduleError {
Status400(models::Errors),
Status401(models::Errors),
Status403(models::Errors),
Status412(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
pub async fn create_scan_all_schedule(configuration: &configuration::Configuration, params: CreateScanAllScheduleParams) -> Result<(), Error<CreateScanAllScheduleError>> {
let uri_str = format!("{}/system/scanAll/schedule", 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());
}
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.schedule);
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(())
} else {
let content = resp.text().await?;
let entity: Option<CreateScanAllScheduleError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_latest_scan_all_metrics(configuration: &configuration::Configuration, params: GetLatestScanAllMetricsParams) -> Result<models::Stats, Error<GetLatestScanAllMetricsError>> {
let uri_str = format!("{}/scans/all/metrics", 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::Stats`"))),
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::Stats`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLatestScanAllMetricsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
#[deprecated]
pub async fn get_latest_scheduled_scan_all_metrics(configuration: &configuration::Configuration, params: GetLatestScheduledScanAllMetricsParams) -> Result<models::Stats, Error<GetLatestScheduledScanAllMetricsError>> {
let uri_str = format!("{}/scans/schedule/metrics", 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::Stats`"))),
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::Stats`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLatestScheduledScanAllMetricsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_scan_all_schedule(configuration: &configuration::Configuration, params: GetScanAllScheduleParams) -> Result<models::Schedule, Error<GetScanAllScheduleError>> {
let uri_str = format!("{}/system/scanAll/schedule", 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::Schedule`"))),
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::Schedule`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScanAllScheduleError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn stop_scan_all(configuration: &configuration::Configuration, params: StopScanAllParams) -> Result<(), Error<StopScanAllError>> {
let uri_str = format!("{}/system/scanAll/stop", 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());
}
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(())
} else {
let content = resp.text().await?;
let entity: Option<StopScanAllError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_scan_all_schedule(configuration: &configuration::Configuration, params: UpdateScanAllScheduleParams) -> Result<(), Error<UpdateScanAllScheduleError>> {
let uri_str = format!("{}/system/scanAll/schedule", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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());
};
req_builder = req_builder.json(¶ms.schedule);
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(())
} else {
let content = resp.text().await?;
let entity: Option<UpdateScanAllScheduleError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}