euvd 0.2.0

API for querying recent vulnerabilities from the ENISA EUVD database.
Documentation
/*
 * EUVD API
 *
 * API for querying recent vulnerabilities from the ENISA EUVD database.
 *
 * The version of the OpenAPI document: 0.2.0
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`get_advisory_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAdvisoryByIdError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_by_enisa_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetByEnisaIdError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_critical_vulnerabilities`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCriticalVulnerabilitiesError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_exploited_vulnerabilities`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetExploitedVulnerabilitiesError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_last_vulnerabilities`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLastVulnerabilitiesError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_vulnerability_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVulnerabilityByIdError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`query_vulnerabilities`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum QueryVulnerabilitiesError {
    UnknownValue(serde_json::Value),
}


pub async fn get_advisory_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Advisory, Error<GetAdvisoryByIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_id = id;

    let uri_str = format!("{}/api/advisory", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("id", &p_id.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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::Advisory`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetAdvisoryByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_by_enisa_id(configuration: &configuration::Configuration, id: &str) -> Result<models::VulnerabilityWithRelations, Error<GetByEnisaIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_id = id;

    let uri_str = format!("{}/api/enisaid", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("id", &p_id.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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::VulnerabilityWithRelations`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetByEnisaIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_critical_vulnerabilities(configuration: &configuration::Configuration, ) -> Result<Vec<models::Vulnerability>, Error<GetCriticalVulnerabilitiesError>> {

    let uri_str = format!("{}/api/criticalvulnerabilities", 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());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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&lt;models::Vulnerability&gt;`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetCriticalVulnerabilitiesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_exploited_vulnerabilities(configuration: &configuration::Configuration, ) -> Result<Vec<models::Vulnerability>, Error<GetExploitedVulnerabilitiesError>> {

    let uri_str = format!("{}/api/exploitedvulnerabilities", 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());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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&lt;models::Vulnerability&gt;`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetExploitedVulnerabilitiesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_last_vulnerabilities(configuration: &configuration::Configuration, ) -> Result<Vec<models::Vulnerability>, Error<GetLastVulnerabilitiesError>> {

    let uri_str = format!("{}/api/lastvulnerabilities", 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());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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&lt;models::Vulnerability&gt;`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetLastVulnerabilitiesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_vulnerability_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::VulnerabilityWithComponents, Error<GetVulnerabilityByIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_id = id;

    let uri_str = format!("{}/api/vulnerability", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("id", &p_id.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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::VulnerabilityWithComponents`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetVulnerabilityByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn query_vulnerabilities(configuration: &configuration::Configuration, from_score: Option<f32>, to_score: Option<f32>, from_epss: Option<f32>, to_epss: Option<f32>, from_date: Option<String>, to_date: Option<String>, product: Option<&str>, vendor: Option<&str>, assigner: Option<&str>, exploited: Option<bool>, page: Option<i32>, text: Option<&str>, size: Option<i32>) -> Result<models::Vulnerabilities, Error<QueryVulnerabilitiesError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_from_score = from_score;
    let p_to_score = to_score;
    let p_from_epss = from_epss;
    let p_to_epss = to_epss;
    let p_from_date = from_date;
    let p_to_date = to_date;
    let p_product = product;
    let p_vendor = vendor;
    let p_assigner = assigner;
    let p_exploited = exploited;
    let p_page = page;
    let p_text = text;
    let p_size = size;

    let uri_str = format!("{}/api/vulnerabilities", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_from_score {
        req_builder = req_builder.query(&[("fromScore", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_to_score {
        req_builder = req_builder.query(&[("toScore", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_from_epss {
        req_builder = req_builder.query(&[("fromEpss", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_to_epss {
        req_builder = req_builder.query(&[("toEpss", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_from_date {
        req_builder = req_builder.query(&[("fromDate", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_to_date {
        req_builder = req_builder.query(&[("toDate", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_product {
        req_builder = req_builder.query(&[("product", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_vendor {
        req_builder = req_builder.query(&[("vendor", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_assigner {
        req_builder = req_builder.query(&[("assigner", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_exploited {
        req_builder = req_builder.query(&[("exploited", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_page {
        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_text {
        req_builder = req_builder.query(&[("text", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_size {
        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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 => serde_json::from_str(&content).map_err(Error::from),
            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::Vulnerabilities`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<QueryVulnerabilitiesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}