harbor_api/apis/
securityhub_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct GetSecuritySummaryParams {
20 pub x_request_id: Option<String>,
22 pub with_dangerous_cve: Option<bool>,
24 pub with_dangerous_artifact: Option<bool>
26}
27
28#[derive(Clone, Debug)]
30pub struct ListVulnerabilitiesParams {
31 pub x_request_id: Option<String>,
33 pub q: Option<String>,
35 pub page: Option<i64>,
37 pub page_size: Option<i64>,
39 pub tune_count: Option<bool>,
41 pub with_tag: Option<bool>
43}
44
45
46#[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#[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
68pub 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", ¶m_value.to_string())]);
76 }
77 if let Some(ref param_value) = params.with_dangerous_artifact {
78 req_builder = req_builder.query(&[("with_dangerous_artifact", ¶m_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
115pub 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", ¶m_value.to_string())]);
123 }
124 if let Some(ref param_value) = params.page {
125 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
126 }
127 if let Some(ref param_value) = params.page_size {
128 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
129 }
130 if let Some(ref param_value) = params.tune_count {
131 req_builder = req_builder.query(&[("tune_count", ¶m_value.to_string())]);
132 }
133 if let Some(ref param_value) = params.with_tag {
134 req_builder = req_builder.query(&[("with_tag", ¶m_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<models::VulnerabilityItem>`"))),
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<models::VulnerabilityItem>`")))),
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