harbor_api/apis/
scan_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_report_log`]
18#[derive(Clone, Debug)]
19pub struct GetReportLogParams {
20    /// The name of the project
21    pub project_name: String,
22    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
23    pub repository_name: String,
24    /// The reference of the artifact, can be digest or tag
25    pub reference: String,
26    /// The report id to get the log
27    pub report_id: String,
28    /// An unique ID for the request
29    pub x_request_id: Option<String>
30}
31
32/// struct for passing parameters to the method [`scan_artifact`]
33#[derive(Clone, Debug)]
34pub struct ScanArtifactParams {
35    /// The name of the project
36    pub project_name: String,
37    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
38    pub repository_name: String,
39    /// The reference of the artifact, can be digest or tag
40    pub reference: String,
41    /// An unique ID for the request
42    pub x_request_id: Option<String>,
43    pub scan_type: Option<models::HarborScanType>
44}
45
46/// struct for passing parameters to the method [`stop_scan_artifact`]
47#[derive(Clone, Debug)]
48pub struct StopScanArtifactParams {
49    /// The name of the project
50    pub project_name: String,
51    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
52    pub repository_name: String,
53    /// The reference of the artifact, can be digest or tag
54    pub reference: String,
55    /// The scan type: Vulnerabilities, SBOM
56    pub scan_type: models::HarborScanType,
57    /// An unique ID for the request
58    pub x_request_id: Option<String>
59}
60
61
62/// struct for typed errors of method [`get_report_log`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum GetReportLogError {
66    Status400(models::Errors),
67    Status401(models::Errors),
68    Status403(models::Errors),
69    Status404(models::Errors),
70    Status500(models::Errors),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`scan_artifact`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ScanArtifactError {
78    Status400(models::Errors),
79    Status401(models::Errors),
80    Status403(models::Errors),
81    Status404(models::Errors),
82    Status422(models::Errors),
83    Status500(models::Errors),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`stop_scan_artifact`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum StopScanArtifactError {
91    Status400(models::Errors),
92    Status401(models::Errors),
93    Status403(models::Errors),
94    Status404(models::Errors),
95    Status422(models::Errors),
96    Status500(models::Errors),
97    UnknownValue(serde_json::Value),
98}
99
100
101/// Get the log of the scan report
102pub async fn get_report_log(configuration: &configuration::Configuration, params: GetReportLogParams) -> Result<String, Error<GetReportLogError>> {
103
104    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/scan/{report_id}/log", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name), reference=crate::apis::urlencode(params.reference), report_id=crate::apis::urlencode(params.report_id));
105    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
106
107    if let Some(ref user_agent) = configuration.user_agent {
108        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109    }
110    if let Some(param_value) = params.x_request_id {
111        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
112    }
113    if let Some(ref auth_conf) = configuration.basic_auth {
114        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Ok(content),
133            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<GetReportLogError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Scan the specified artifact
143pub async fn scan_artifact(configuration: &configuration::Configuration, params: ScanArtifactParams) -> Result<(), Error<ScanArtifactError>> {
144
145    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/scan", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name), reference=crate::apis::urlencode(params.reference));
146    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
147
148    if let Some(ref user_agent) = configuration.user_agent {
149        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
150    }
151    if let Some(param_value) = params.x_request_id {
152        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
153    }
154    if let Some(ref auth_conf) = configuration.basic_auth {
155        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
156    };
157    req_builder = req_builder.json(&params.scan_type);
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163
164    if !status.is_client_error() && !status.is_server_error() {
165        Ok(())
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<ScanArtifactError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// Cancelling a scan job for a particular artifact
174pub async fn stop_scan_artifact(configuration: &configuration::Configuration, params: StopScanArtifactParams) -> Result<(), Error<StopScanArtifactError>> {
175
176    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/scan/stop", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name), reference=crate::apis::urlencode(params.reference));
177    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
178
179    if let Some(ref user_agent) = configuration.user_agent {
180        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181    }
182    if let Some(param_value) = params.x_request_id {
183        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
184    }
185    if let Some(ref auth_conf) = configuration.basic_auth {
186        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
187    };
188    req_builder = req_builder.json(&params.scan_type);
189
190    let req = req_builder.build()?;
191    let resp = configuration.client.execute(req).await?;
192
193    let status = resp.status();
194
195    if !status.is_client_error() && !status.is_server_error() {
196        Ok(())
197    } else {
198        let content = resp.text().await?;
199        let entity: Option<StopScanArtifactError> = serde_json::from_str(&content).ok();
200        Err(Error::ResponseError(ResponseContent { status, content, entity }))
201    }
202}
203