harbor_api/apis/
scan_all_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 [`create_scan_all_schedule`]
18#[derive(Clone, Debug)]
19pub struct CreateScanAllScheduleParams {
20    /// Create a schedule or a manual trigger for the scan all job.
21    pub schedule: models::Schedule,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`get_latest_scan_all_metrics`]
27#[derive(Clone, Debug)]
28pub struct GetLatestScanAllMetricsParams {
29    /// An unique ID for the request
30    pub x_request_id: Option<String>
31}
32
33/// struct for passing parameters to the method [`get_latest_scheduled_scan_all_metrics`]
34#[derive(Clone, Debug)]
35pub struct GetLatestScheduledScanAllMetricsParams {
36    /// An unique ID for the request
37    pub x_request_id: Option<String>
38}
39
40/// struct for passing parameters to the method [`get_scan_all_schedule`]
41#[derive(Clone, Debug)]
42pub struct GetScanAllScheduleParams {
43    /// An unique ID for the request
44    pub x_request_id: Option<String>
45}
46
47/// struct for passing parameters to the method [`stop_scan_all`]
48#[derive(Clone, Debug)]
49pub struct StopScanAllParams {
50    /// An unique ID for the request
51    pub x_request_id: Option<String>
52}
53
54/// struct for passing parameters to the method [`update_scan_all_schedule`]
55#[derive(Clone, Debug)]
56pub struct UpdateScanAllScheduleParams {
57    /// Updates the schedule of scan all job, which scans all of images in Harbor.
58    pub schedule: models::Schedule,
59    /// An unique ID for the request
60    pub x_request_id: Option<String>
61}
62
63
64/// struct for typed errors of method [`create_scan_all_schedule`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum CreateScanAllScheduleError {
68    Status400(models::Errors),
69    Status401(models::Errors),
70    Status403(models::Errors),
71    Status409(models::Errors),
72    Status412(models::Errors),
73    Status500(models::Errors),
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`get_latest_scan_all_metrics`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum GetLatestScanAllMetricsError {
81    Status401(models::Errors),
82    Status403(models::Errors),
83    Status412(models::Errors),
84    Status500(models::Errors),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`get_latest_scheduled_scan_all_metrics`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetLatestScheduledScanAllMetricsError {
92    Status401(models::Errors),
93    Status403(models::Errors),
94    Status412(models::Errors),
95    Status500(models::Errors),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`get_scan_all_schedule`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetScanAllScheduleError {
103    Status401(models::Errors),
104    Status403(models::Errors),
105    Status412(models::Errors),
106    Status500(models::Errors),
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`stop_scan_all`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum StopScanAllError {
114    Status400(models::Errors),
115    Status401(models::Errors),
116    Status403(models::Errors),
117    Status500(models::Errors),
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`update_scan_all_schedule`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum UpdateScanAllScheduleError {
125    Status400(models::Errors),
126    Status401(models::Errors),
127    Status403(models::Errors),
128    Status412(models::Errors),
129    Status500(models::Errors),
130    UnknownValue(serde_json::Value),
131}
132
133
134/// This endpoint is for creating a schedule or a manual trigger for the scan all job, which scans all of images in Harbor.
135pub async fn create_scan_all_schedule(configuration: &configuration::Configuration, params: CreateScanAllScheduleParams) -> Result<(), Error<CreateScanAllScheduleError>> {
136
137    let uri_str = format!("{}/system/scanAll/schedule", configuration.base_path);
138    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(param_value) = params.x_request_id {
144        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
145    }
146    if let Some(ref auth_conf) = configuration.basic_auth {
147        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
148    };
149    req_builder = req_builder.json(&params.schedule);
150
151    let req = req_builder.build()?;
152    let resp = configuration.client.execute(req).await?;
153
154    let status = resp.status();
155
156    if !status.is_client_error() && !status.is_server_error() {
157        Ok(())
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<CreateScanAllScheduleError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent { status, content, entity }))
162    }
163}
164
165/// Get the metrics of the latest scan all process
166pub async fn get_latest_scan_all_metrics(configuration: &configuration::Configuration, params: GetLatestScanAllMetricsParams) -> Result<models::Stats, Error<GetLatestScanAllMetricsError>> {
167
168    let uri_str = format!("{}/scans/all/metrics", configuration.base_path);
169    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
170
171    if let Some(ref user_agent) = configuration.user_agent {
172        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
173    }
174    if let Some(param_value) = params.x_request_id {
175        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
176    }
177    if let Some(ref auth_conf) = configuration.basic_auth {
178        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
179    };
180
181    let req = req_builder.build()?;
182    let resp = configuration.client.execute(req).await?;
183
184    let status = resp.status();
185    let content_type = resp
186        .headers()
187        .get("content-type")
188        .and_then(|v| v.to_str().ok())
189        .unwrap_or("application/octet-stream");
190    let content_type = super::ContentType::from(content_type);
191
192    if !status.is_client_error() && !status.is_server_error() {
193        let content = resp.text().await?;
194        match content_type {
195            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Stats`"))),
197            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::Stats`")))),
198        }
199    } else {
200        let content = resp.text().await?;
201        let entity: Option<GetLatestScanAllMetricsError> = serde_json::from_str(&content).ok();
202        Err(Error::ResponseError(ResponseContent { status, content, entity }))
203    }
204}
205
206/// Get the metrics of the latest scheduled scan all process
207#[deprecated]
208pub async fn get_latest_scheduled_scan_all_metrics(configuration: &configuration::Configuration, params: GetLatestScheduledScanAllMetricsParams) -> Result<models::Stats, Error<GetLatestScheduledScanAllMetricsError>> {
209
210    let uri_str = format!("{}/scans/schedule/metrics", configuration.base_path);
211    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
212
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(param_value) = params.x_request_id {
217        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
218    }
219    if let Some(ref auth_conf) = configuration.basic_auth {
220        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
221    };
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227    let content_type = resp
228        .headers()
229        .get("content-type")
230        .and_then(|v| v.to_str().ok())
231        .unwrap_or("application/octet-stream");
232    let content_type = super::ContentType::from(content_type);
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        match content_type {
237            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Stats`"))),
239            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::Stats`")))),
240        }
241    } else {
242        let content = resp.text().await?;
243        let entity: Option<GetLatestScheduledScanAllMetricsError> = serde_json::from_str(&content).ok();
244        Err(Error::ResponseError(ResponseContent { status, content, entity }))
245    }
246}
247
248/// This endpoint is for getting a schedule for the scan all job, which scans all of images in Harbor.
249pub async fn get_scan_all_schedule(configuration: &configuration::Configuration, params: GetScanAllScheduleParams) -> Result<models::Schedule, Error<GetScanAllScheduleError>> {
250
251    let uri_str = format!("{}/system/scanAll/schedule", configuration.base_path);
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref user_agent) = configuration.user_agent {
255        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256    }
257    if let Some(param_value) = params.x_request_id {
258        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
259    }
260    if let Some(ref auth_conf) = configuration.basic_auth {
261        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
262    };
263
264    let req = req_builder.build()?;
265    let resp = configuration.client.execute(req).await?;
266
267    let status = resp.status();
268    let content_type = resp
269        .headers()
270        .get("content-type")
271        .and_then(|v| v.to_str().ok())
272        .unwrap_or("application/octet-stream");
273    let content_type = super::ContentType::from(content_type);
274
275    if !status.is_client_error() && !status.is_server_error() {
276        let content = resp.text().await?;
277        match content_type {
278            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
279            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Schedule`"))),
280            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::Schedule`")))),
281        }
282    } else {
283        let content = resp.text().await?;
284        let entity: Option<GetScanAllScheduleError> = serde_json::from_str(&content).ok();
285        Err(Error::ResponseError(ResponseContent { status, content, entity }))
286    }
287}
288
289/// Stop scanAll job execution
290pub async fn stop_scan_all(configuration: &configuration::Configuration, params: StopScanAllParams) -> Result<(), Error<StopScanAllError>> {
291
292    let uri_str = format!("{}/system/scanAll/stop", configuration.base_path);
293    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
294
295    if let Some(ref user_agent) = configuration.user_agent {
296        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
297    }
298    if let Some(param_value) = params.x_request_id {
299        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
300    }
301    if let Some(ref auth_conf) = configuration.basic_auth {
302        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
303    };
304
305    let req = req_builder.build()?;
306    let resp = configuration.client.execute(req).await?;
307
308    let status = resp.status();
309
310    if !status.is_client_error() && !status.is_server_error() {
311        Ok(())
312    } else {
313        let content = resp.text().await?;
314        let entity: Option<StopScanAllError> = serde_json::from_str(&content).ok();
315        Err(Error::ResponseError(ResponseContent { status, content, entity }))
316    }
317}
318
319/// This endpoint is for updating the schedule of scan all job, which scans all of images in Harbor.
320pub async fn update_scan_all_schedule(configuration: &configuration::Configuration, params: UpdateScanAllScheduleParams) -> Result<(), Error<UpdateScanAllScheduleError>> {
321
322    let uri_str = format!("{}/system/scanAll/schedule", configuration.base_path);
323    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
324
325    if let Some(ref user_agent) = configuration.user_agent {
326        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
327    }
328    if let Some(param_value) = params.x_request_id {
329        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
330    }
331    if let Some(ref auth_conf) = configuration.basic_auth {
332        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
333    };
334    req_builder = req_builder.json(&params.schedule);
335
336    let req = req_builder.build()?;
337    let resp = configuration.client.execute(req).await?;
338
339    let status = resp.status();
340
341    if !status.is_client_error() && !status.is_server_error() {
342        Ok(())
343    } else {
344        let content = resp.text().await?;
345        let entity: Option<UpdateScanAllScheduleError> = serde_json::from_str(&content).ok();
346        Err(Error::ResponseError(ResponseContent { status, content, entity }))
347    }
348}
349