harbor_api/apis/
purge_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_purge_schedule`]
18#[derive(Clone, Debug)]
19pub struct CreatePurgeScheduleParams {
20    /// The purge job's schedule, it is a json object. | The sample format is | {\"parameters\":{\"audit_retention_hour\":168,\"dry_run\":true, \"include_operations\":\"create,delete,pull\"},\"schedule\":{\"type\":\"Hourly\",\"cron\":\"0 0 * * * *\"}} | the include_operation should be a comma separated string, e.g. create,delete,pull, if it is empty, no operation will be purged. 
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_purge_history`]
27#[derive(Clone, Debug)]
28pub struct GetPurgeHistoryParams {
29    /// An unique ID for the request
30    pub x_request_id: Option<String>,
31    /// 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]
32    pub q: Option<String>,
33    /// Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending order and field2 in descending order with \"sort=field1,-field2\"
34    pub sort: Option<String>,
35    /// The page number
36    pub page: Option<i64>,
37    /// The size of per page
38    pub page_size: Option<i64>
39}
40
41/// struct for passing parameters to the method [`get_purge_job`]
42#[derive(Clone, Debug)]
43pub struct GetPurgeJobParams {
44    /// The ID of the purge log
45    pub purge_id: i64,
46    /// An unique ID for the request
47    pub x_request_id: Option<String>
48}
49
50/// struct for passing parameters to the method [`get_purge_job_log`]
51#[derive(Clone, Debug)]
52pub struct GetPurgeJobLogParams {
53    /// The ID of the purge log
54    pub purge_id: i64,
55    /// An unique ID for the request
56    pub x_request_id: Option<String>
57}
58
59/// struct for passing parameters to the method [`get_purge_schedule`]
60#[derive(Clone, Debug)]
61pub struct GetPurgeScheduleParams {
62    /// An unique ID for the request
63    pub x_request_id: Option<String>
64}
65
66/// struct for passing parameters to the method [`stop_purge`]
67#[derive(Clone, Debug)]
68pub struct StopPurgeParams {
69    /// The ID of the purge log
70    pub purge_id: i64,
71    /// An unique ID for the request
72    pub x_request_id: Option<String>
73}
74
75/// struct for passing parameters to the method [`update_purge_schedule`]
76#[derive(Clone, Debug)]
77pub struct UpdatePurgeScheduleParams {
78    /// The purge job's schedule, it is a json object. | The sample format is | {\"parameters\":{\"audit_retention_hour\":168,\"dry_run\":true, \"include_operations\":\"create,delete,pull\"},\"schedule\":{\"type\":\"Hourly\",\"cron\":\"0 0 * * * *\"}} | the include_operation should be a comma separated string, e.g. create,delete,pull, if it is empty, no operation will be purged. 
79    pub schedule: models::Schedule,
80    /// An unique ID for the request
81    pub x_request_id: Option<String>
82}
83
84
85/// struct for typed errors of method [`create_purge_schedule`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum CreatePurgeScheduleError {
89    Status400(models::Errors),
90    Status401(models::Errors),
91    Status403(models::Errors),
92    Status500(models::Errors),
93    UnknownValue(serde_json::Value),
94}
95
96/// struct for typed errors of method [`get_purge_history`]
97#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum GetPurgeHistoryError {
100    Status401(models::Errors),
101    Status403(models::Errors),
102    Status500(models::Errors),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`get_purge_job`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetPurgeJobError {
110    Status401(models::Errors),
111    Status403(models::Errors),
112    Status404(models::Errors),
113    Status500(models::Errors),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`get_purge_job_log`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum GetPurgeJobLogError {
121    Status400(models::Errors),
122    Status401(models::Errors),
123    Status403(models::Errors),
124    Status404(models::Errors),
125    Status500(models::Errors),
126    UnknownValue(serde_json::Value),
127}
128
129/// struct for typed errors of method [`get_purge_schedule`]
130#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(untagged)]
132pub enum GetPurgeScheduleError {
133    Status401(models::Errors),
134    Status403(models::Errors),
135    Status500(models::Errors),
136    UnknownValue(serde_json::Value),
137}
138
139/// struct for typed errors of method [`stop_purge`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum StopPurgeError {
143    Status401(models::Errors),
144    Status403(models::Errors),
145    Status404(models::Errors),
146    Status500(models::Errors),
147    UnknownValue(serde_json::Value),
148}
149
150/// struct for typed errors of method [`update_purge_schedule`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum UpdatePurgeScheduleError {
154    Status400(models::Errors),
155    Status401(models::Errors),
156    Status403(models::Errors),
157    Status500(models::Errors),
158    UnknownValue(serde_json::Value),
159}
160
161
162/// This endpoint is for update purge job schedule. 
163pub async fn create_purge_schedule(configuration: &configuration::Configuration, params: CreatePurgeScheduleParams) -> Result<(), Error<CreatePurgeScheduleError>> {
164
165    let uri_str = format!("{}/system/purgeaudit/schedule", configuration.base_path);
166    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
167
168    if let Some(ref user_agent) = configuration.user_agent {
169        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
170    }
171    if let Some(param_value) = params.x_request_id {
172        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
173    }
174    if let Some(ref auth_conf) = configuration.basic_auth {
175        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
176    };
177    req_builder = req_builder.json(&params.schedule);
178
179    let req = req_builder.build()?;
180    let resp = configuration.client.execute(req).await?;
181
182    let status = resp.status();
183
184    if !status.is_client_error() && !status.is_server_error() {
185        Ok(())
186    } else {
187        let content = resp.text().await?;
188        let entity: Option<CreatePurgeScheduleError> = serde_json::from_str(&content).ok();
189        Err(Error::ResponseError(ResponseContent { status, content, entity }))
190    }
191}
192
193/// get purge job execution history.
194pub async fn get_purge_history(configuration: &configuration::Configuration, params: GetPurgeHistoryParams) -> Result<Vec<models::ExecHistory>, Error<GetPurgeHistoryError>> {
195
196    let uri_str = format!("{}/system/purgeaudit", configuration.base_path);
197    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
198
199    if let Some(ref param_value) = params.q {
200        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
201    }
202    if let Some(ref param_value) = params.sort {
203        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
204    }
205    if let Some(ref param_value) = params.page {
206        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
207    }
208    if let Some(ref param_value) = params.page_size {
209        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
210    }
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(param_value) = params.x_request_id {
215        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
216    }
217    if let Some(ref auth_conf) = configuration.basic_auth {
218        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
219    };
220
221    let req = req_builder.build()?;
222    let resp = configuration.client.execute(req).await?;
223
224    let status = resp.status();
225    let content_type = resp
226        .headers()
227        .get("content-type")
228        .and_then(|v| v.to_str().ok())
229        .unwrap_or("application/octet-stream");
230    let content_type = super::ContentType::from(content_type);
231
232    if !status.is_client_error() && !status.is_server_error() {
233        let content = resp.text().await?;
234        match content_type {
235            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
236            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ExecHistory&gt;`"))),
237            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::ExecHistory&gt;`")))),
238        }
239    } else {
240        let content = resp.text().await?;
241        let entity: Option<GetPurgeHistoryError> = serde_json::from_str(&content).ok();
242        Err(Error::ResponseError(ResponseContent { status, content, entity }))
243    }
244}
245
246/// This endpoint let user get purge job status filtered by specific ID.
247pub async fn get_purge_job(configuration: &configuration::Configuration, params: GetPurgeJobParams) -> Result<models::ExecHistory, Error<GetPurgeJobError>> {
248
249    let uri_str = format!("{}/system/purgeaudit/{purge_id}", configuration.base_path, purge_id=params.purge_id);
250    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
251
252    if let Some(ref user_agent) = configuration.user_agent {
253        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
254    }
255    if let Some(param_value) = params.x_request_id {
256        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
257    }
258    if let Some(ref auth_conf) = configuration.basic_auth {
259        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
260    };
261
262    let req = req_builder.build()?;
263    let resp = configuration.client.execute(req).await?;
264
265    let status = resp.status();
266    let content_type = resp
267        .headers()
268        .get("content-type")
269        .and_then(|v| v.to_str().ok())
270        .unwrap_or("application/octet-stream");
271    let content_type = super::ContentType::from(content_type);
272
273    if !status.is_client_error() && !status.is_server_error() {
274        let content = resp.text().await?;
275        match content_type {
276            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
277            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExecHistory`"))),
278            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::ExecHistory`")))),
279        }
280    } else {
281        let content = resp.text().await?;
282        let entity: Option<GetPurgeJobError> = serde_json::from_str(&content).ok();
283        Err(Error::ResponseError(ResponseContent { status, content, entity }))
284    }
285}
286
287/// This endpoint let user get purge job logs filtered by specific ID.
288pub async fn get_purge_job_log(configuration: &configuration::Configuration, params: GetPurgeJobLogParams) -> Result<String, Error<GetPurgeJobLogError>> {
289
290    let uri_str = format!("{}/system/purgeaudit/{purge_id}/log", configuration.base_path, purge_id=params.purge_id);
291    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
292
293    if let Some(ref user_agent) = configuration.user_agent {
294        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295    }
296    if let Some(param_value) = params.x_request_id {
297        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
298    }
299    if let Some(ref auth_conf) = configuration.basic_auth {
300        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
301    };
302
303    let req = req_builder.build()?;
304    let resp = configuration.client.execute(req).await?;
305
306    let status = resp.status();
307    let content_type = resp
308        .headers()
309        .get("content-type")
310        .and_then(|v| v.to_str().ok())
311        .unwrap_or("application/octet-stream");
312    let content_type = super::ContentType::from(content_type);
313
314    if !status.is_client_error() && !status.is_server_error() {
315        let content = resp.text().await?;
316        match content_type {
317            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
318            ContentType::Text => return Ok(content),
319            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`")))),
320        }
321    } else {
322        let content = resp.text().await?;
323        let entity: Option<GetPurgeJobLogError> = serde_json::from_str(&content).ok();
324        Err(Error::ResponseError(ResponseContent { status, content, entity }))
325    }
326}
327
328/// This endpoint is for get schedule of purge job.
329pub async fn get_purge_schedule(configuration: &configuration::Configuration, params: GetPurgeScheduleParams) -> Result<models::ExecHistory, Error<GetPurgeScheduleError>> {
330
331    let uri_str = format!("{}/system/purgeaudit/schedule", configuration.base_path);
332    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
333
334    if let Some(ref user_agent) = configuration.user_agent {
335        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336    }
337    if let Some(param_value) = params.x_request_id {
338        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
339    }
340    if let Some(ref auth_conf) = configuration.basic_auth {
341        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
342    };
343
344    let req = req_builder.build()?;
345    let resp = configuration.client.execute(req).await?;
346
347    let status = resp.status();
348    let content_type = resp
349        .headers()
350        .get("content-type")
351        .and_then(|v| v.to_str().ok())
352        .unwrap_or("application/octet-stream");
353    let content_type = super::ContentType::from(content_type);
354
355    if !status.is_client_error() && !status.is_server_error() {
356        let content = resp.text().await?;
357        match content_type {
358            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
359            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExecHistory`"))),
360            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::ExecHistory`")))),
361        }
362    } else {
363        let content = resp.text().await?;
364        let entity: Option<GetPurgeScheduleError> = serde_json::from_str(&content).ok();
365        Err(Error::ResponseError(ResponseContent { status, content, entity }))
366    }
367}
368
369/// Stop the purge audit log execution specified by ID
370pub async fn stop_purge(configuration: &configuration::Configuration, params: StopPurgeParams) -> Result<(), Error<StopPurgeError>> {
371
372    let uri_str = format!("{}/system/purgeaudit/{purge_id}", configuration.base_path, purge_id=params.purge_id);
373    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
374
375    if let Some(ref user_agent) = configuration.user_agent {
376        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
377    }
378    if let Some(param_value) = params.x_request_id {
379        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
380    }
381    if let Some(ref auth_conf) = configuration.basic_auth {
382        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
383    };
384
385    let req = req_builder.build()?;
386    let resp = configuration.client.execute(req).await?;
387
388    let status = resp.status();
389
390    if !status.is_client_error() && !status.is_server_error() {
391        Ok(())
392    } else {
393        let content = resp.text().await?;
394        let entity: Option<StopPurgeError> = serde_json::from_str(&content).ok();
395        Err(Error::ResponseError(ResponseContent { status, content, entity }))
396    }
397}
398
399/// This endpoint is for update purge job schedule. 
400pub async fn update_purge_schedule(configuration: &configuration::Configuration, params: UpdatePurgeScheduleParams) -> Result<(), Error<UpdatePurgeScheduleError>> {
401
402    let uri_str = format!("{}/system/purgeaudit/schedule", configuration.base_path);
403    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
404
405    if let Some(ref user_agent) = configuration.user_agent {
406        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
407    }
408    if let Some(param_value) = params.x_request_id {
409        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
410    }
411    if let Some(ref auth_conf) = configuration.basic_auth {
412        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
413    };
414    req_builder = req_builder.json(&params.schedule);
415
416    let req = req_builder.build()?;
417    let resp = configuration.client.execute(req).await?;
418
419    let status = resp.status();
420
421    if !status.is_client_error() && !status.is_server_error() {
422        Ok(())
423    } else {
424        let content = resp.text().await?;
425        let entity: Option<UpdatePurgeScheduleError> = serde_json::from_str(&content).ok();
426        Err(Error::ResponseError(ResponseContent { status, content, entity }))
427    }
428}
429