harbor-api 2.0.0

These APIs provide services for manipulating Harbor project.
Documentation
/*
 * Harbor API
 *
 * These APIs provide services for manipulating Harbor project.
 *
 * The version of the OpenAPI document: 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 passing parameters to the method [`download_scan_data`]
#[derive(Clone, Debug)]
pub struct DownloadScanDataParams {
    /// Execution ID
    pub execution_id: i32,
    /// An unique ID for the request
    pub x_request_id: Option<String>,
    /// The format of the data to be exported. e.g. CSV or PDF
    pub format: Option<String>
}

/// struct for passing parameters to the method [`export_scan_data`]
#[derive(Clone, Debug)]
pub struct ExportScanDataParams {
    /// The type of scan data to export
    pub x_scan_data_type: String,
    /// The criteria for the export
    pub criteria: models::ScanDataExportRequest,
    /// An unique ID for the request
    pub x_request_id: Option<String>
}

/// struct for passing parameters to the method [`get_scan_data_export_execution`]
#[derive(Clone, Debug)]
pub struct GetScanDataExportExecutionParams {
    /// Execution ID
    pub execution_id: i32,
    /// An unique ID for the request
    pub x_request_id: Option<String>
}

/// struct for passing parameters to the method [`get_scan_data_export_execution_list`]
#[derive(Clone, Debug)]
pub struct GetScanDataExportExecutionListParams {
    /// An unique ID for the request
    pub x_request_id: Option<String>
}


/// struct for typed errors of method [`download_scan_data`]
#[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),
}

/// struct for typed errors of method [`export_scan_data`]
#[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),
}

/// struct for typed errors of method [`get_scan_data_export_execution`]
#[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),
}

/// struct for typed errors of method [`get_scan_data_export_execution_list`]
#[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),
}


/// Download the scan data report. Default format is CSV
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", &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());
    }
    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 }))
    }
}

/// Export scan data for selected projects
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(&params.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 }))
    }
}

/// Get the scan data export execution specified by ID
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 }))
    }
}

/// Get a list of specific scan data export execution jobs for a specified user
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 }))
    }
}