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