use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug)]
pub struct CreateScannerParams {
pub registration: models::ScannerRegistrationReq,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct DeleteScannerParams {
pub registration_id: String,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetScannerParams {
pub registration_id: String,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct GetScannerMetadataParams {
pub registration_id: String,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct ListScannersParams {
pub x_request_id: Option<String>,
pub q: Option<String>,
pub sort: Option<String>,
pub page: Option<i64>,
pub page_size: Option<i64>
}
#[derive(Clone, Debug)]
pub struct PingScannerParams {
pub settings: models::ScannerRegistrationSettings,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct SetScannerAsDefaultParams {
pub registration_id: String,
pub payload: models::IsDefault,
pub x_request_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct UpdateScannerParams {
pub registration_id: String,
pub registration: models::ScannerRegistrationReq,
pub x_request_id: Option<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateScannerError {
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 DeleteScannerError {
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 GetScannerError {
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 GetScannerMetadataError {
Status401(models::Errors),
Status403(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListScannersError {
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 PingScannerError {
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 SetScannerAsDefaultError {
Status401(models::Errors),
Status403(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateScannerError {
Status401(models::Errors),
Status403(models::Errors),
Status404(models::Errors),
Status500(models::Errors),
UnknownValue(serde_json::Value),
}
pub async fn create_scanner(configuration: &configuration::Configuration, params: CreateScannerParams) -> Result<(), Error<CreateScannerError>> {
let uri_str = format!("{}/scanners", 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.registration);
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<CreateScannerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn delete_scanner(configuration: &configuration::Configuration, params: DeleteScannerParams) -> Result<models::ScannerRegistration, Error<DeleteScannerError>> {
let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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::ScannerRegistration`"))),
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::ScannerRegistration`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteScannerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_scanner(configuration: &configuration::Configuration, params: GetScannerParams) -> Result<models::ScannerRegistration, Error<GetScannerError>> {
let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_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::ScannerRegistration`"))),
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::ScannerRegistration`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScannerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_scanner_metadata(configuration: &configuration::Configuration, params: GetScannerMetadataParams) -> Result<models::ScannerAdapterMetadata, Error<GetScannerMetadataError>> {
let uri_str = format!("{}/scanners/{registration_id}/metadata", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_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::ScannerAdapterMetadata`"))),
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::ScannerAdapterMetadata`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScannerMetadataError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_scanners(configuration: &configuration::Configuration, params: ListScannersParams) -> Result<Vec<models::ScannerRegistration>, Error<ListScannersError>> {
let uri_str = format!("{}/scanners", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.q {
req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.sort {
req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.page_size {
req_builder = req_builder.query(&[("page_size", ¶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();
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 `Vec<models::ScannerRegistration>`"))),
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<models::ScannerRegistration>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListScannersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn ping_scanner(configuration: &configuration::Configuration, params: PingScannerParams) -> Result<(), Error<PingScannerError>> {
let uri_str = format!("{}/scanners/ping", 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.settings);
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<PingScannerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn set_scanner_as_default(configuration: &configuration::Configuration, params: SetScannerAsDefaultParams) -> Result<(), Error<SetScannerAsDefaultError>> {
let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &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.payload);
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<SetScannerAsDefaultError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_scanner(configuration: &configuration::Configuration, params: UpdateScannerParams) -> Result<(), Error<UpdateScannerError>> {
let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
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.registration);
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<UpdateScannerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}