harbor_api/apis/
securityhub_api.rs

1/*
2 * Harbor API
3 *
4 * These APIs provide services for manipulating Harbor project.
5 *
6 * The version of the OpenAPI document: 2.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`get_security_summary`]
18#[derive(Clone, Debug)]
19pub struct GetSecuritySummaryParams {
20    /// An unique ID for the request
21    pub x_request_id: Option<String>,
22    /// Specify whether the dangerous CVEs are included inside summary information
23    pub with_dangerous_cve: Option<bool>,
24    /// Specify whether the dangerous Artifact are included inside summary information
25    pub with_dangerous_artifact: Option<bool>
26}
27
28/// struct for passing parameters to the method [`list_vulnerabilities`]
29#[derive(Clone, Debug)]
30pub struct ListVulnerabilitiesParams {
31    /// An unique ID for the request
32    pub x_request_id: Option<String>,
33    /// Query string to query resources. Supported query patterns are \"exact match(k=v)\", \"fuzzy match(k=~v)\", \"range(k=[min~max])\", \"list with union releationship(k={v1 v2 v3})\" and \"list with intersetion relationship(k=(v1 v2 v3))\". The value of range and list can be string(enclosed by \" or '), integer or time(in format \"2020-04-09 02:36:00\"). All of these query patterns should be put in the query string \"q=xxx\" and splitted by \",\". e.g. q=k1=v1,k2=~v2,k3=[min~max]
34    pub q: Option<String>,
35    /// The page number
36    pub page: Option<i64>,
37    /// The size of per page
38    pub page_size: Option<i64>,
39    /// Enable to ignore X-Total-Count when the total count > 1000, if the total count is less than 1000, the real total count is returned, else -1.
40    pub tune_count: Option<bool>,
41    /// Specify whether the tag information is included inside vulnerability information
42    pub with_tag: Option<bool>
43}
44
45
46/// struct for typed errors of method [`get_security_summary`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSecuritySummaryError {
50    Status401(models::Errors),
51    Status403(models::Errors),
52    Status404(models::Errors),
53    Status500(models::Errors),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`list_vulnerabilities`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum ListVulnerabilitiesError {
61    Status400(models::Errors),
62    Status401(models::Errors),
63    Status500(models::Errors),
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Retrieve the vulnerability summary of the system
69pub async fn get_security_summary(configuration: &configuration::Configuration, params: GetSecuritySummaryParams) -> Result<models::SecuritySummary, Error<GetSecuritySummaryError>> {
70
71    let uri_str = format!("{}/security/summary", configuration.base_path);
72    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
73
74    if let Some(ref param_value) = params.with_dangerous_cve {
75        req_builder = req_builder.query(&[("with_dangerous_cve", &param_value.to_string())]);
76    }
77    if let Some(ref param_value) = params.with_dangerous_artifact {
78        req_builder = req_builder.query(&[("with_dangerous_artifact", &param_value.to_string())]);
79    }
80    if let Some(ref user_agent) = configuration.user_agent {
81        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82    }
83    if let Some(param_value) = params.x_request_id {
84        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
85    }
86    if let Some(ref auth_conf) = configuration.basic_auth {
87        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
88    };
89
90    let req = req_builder.build()?;
91    let resp = configuration.client.execute(req).await?;
92
93    let status = resp.status();
94    let content_type = resp
95        .headers()
96        .get("content-type")
97        .and_then(|v| v.to_str().ok())
98        .unwrap_or("application/octet-stream");
99    let content_type = super::ContentType::from(content_type);
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        match content_type {
104            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecuritySummary`"))),
106            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::SecuritySummary`")))),
107        }
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<GetSecuritySummaryError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
112    }
113}
114
115/// Get the vulnerability list. use q to pass the query condition, supported conditions: cve_id(exact match) cvss_score_v3(range condition) severity(exact match) repository_name(exact match) project_id(exact match) package(exact match) tag(exact match) digest(exact match) 
116pub async fn list_vulnerabilities(configuration: &configuration::Configuration, params: ListVulnerabilitiesParams) -> Result<Vec<models::VulnerabilityItem>, Error<ListVulnerabilitiesError>> {
117
118    let uri_str = format!("{}/security/vul", configuration.base_path);
119    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
120
121    if let Some(ref param_value) = params.q {
122        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
123    }
124    if let Some(ref param_value) = params.page {
125        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
126    }
127    if let Some(ref param_value) = params.page_size {
128        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
129    }
130    if let Some(ref param_value) = params.tune_count {
131        req_builder = req_builder.query(&[("tune_count", &param_value.to_string())]);
132    }
133    if let Some(ref param_value) = params.with_tag {
134        req_builder = req_builder.query(&[("with_tag", &param_value.to_string())]);
135    }
136    if let Some(ref user_agent) = configuration.user_agent {
137        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
138    }
139    if let Some(param_value) = params.x_request_id {
140        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
141    }
142    if let Some(ref auth_conf) = configuration.basic_auth {
143        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
144    };
145
146    let req = req_builder.build()?;
147    let resp = configuration.client.execute(req).await?;
148
149    let status = resp.status();
150    let content_type = resp
151        .headers()
152        .get("content-type")
153        .and_then(|v| v.to_str().ok())
154        .unwrap_or("application/octet-stream");
155    let content_type = super::ContentType::from(content_type);
156
157    if !status.is_client_error() && !status.is_server_error() {
158        let content = resp.text().await?;
159        match content_type {
160            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::VulnerabilityItem&gt;`"))),
162            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::VulnerabilityItem&gt;`")))),
163        }
164    } else {
165        let content = resp.text().await?;
166        let entity: Option<ListVulnerabilitiesError> = serde_json::from_str(&content).ok();
167        Err(Error::ResponseError(ResponseContent { status, content, entity }))
168    }
169}
170