harbor_api/apis/
label_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_label`]
18#[derive(Clone, Debug)]
19pub struct CreateLabelParams {
20    /// The json object of label.
21    pub label: models::Label,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`delete_label`]
27#[derive(Clone, Debug)]
28pub struct DeleteLabelParams {
29    /// Label ID
30    pub label_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_label_by_id`]
36#[derive(Clone, Debug)]
37pub struct GetLabelByIdParams {
38    /// Label ID
39    pub label_id: i64,
40    /// An unique ID for the request
41    pub x_request_id: Option<String>
42}
43
44/// struct for passing parameters to the method [`list_labels`]
45#[derive(Clone, Debug)]
46pub struct ListLabelsParams {
47    /// An unique ID for the request
48    pub x_request_id: Option<String>,
49    /// 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]
50    pub q: Option<String>,
51    /// 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\"
52    pub sort: Option<String>,
53    /// The page number
54    pub page: Option<i64>,
55    /// The size of per page
56    pub page_size: Option<i64>,
57    /// The label name.
58    pub name: Option<String>,
59    /// The label scope. Valid values are g and p. g for global labels and p for project labels.
60    pub scope: Option<String>,
61    /// Relevant project ID, required when scope is p.
62    pub project_id: Option<i64>
63}
64
65/// struct for passing parameters to the method [`update_label`]
66#[derive(Clone, Debug)]
67pub struct UpdateLabelParams {
68    /// Label ID
69    pub label_id: i64,
70    /// The updated label json object.
71    pub label: models::Label,
72    /// An unique ID for the request
73    pub x_request_id: Option<String>
74}
75
76
77/// struct for typed errors of method [`create_label`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum CreateLabelError {
81    Status400(models::Errors),
82    Status401(models::Errors),
83    Status409(models::Errors),
84    Status415(models::Errors),
85    Status500(models::Errors),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`delete_label`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum DeleteLabelError {
93    Status400(models::Errors),
94    Status401(models::Errors),
95    Status404(models::Errors),
96    Status500(models::Errors),
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`get_label_by_id`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum GetLabelByIdError {
104    Status401(models::Errors),
105    Status404(models::Errors),
106    Status500(models::Errors),
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`list_labels`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum ListLabelsError {
114    Status400(models::Errors),
115    Status401(models::Errors),
116    Status500(models::Errors),
117    UnknownValue(serde_json::Value),
118}
119
120/// struct for typed errors of method [`update_label`]
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum UpdateLabelError {
124    Status400(models::Errors),
125    Status401(models::Errors),
126    Status404(models::Errors),
127    Status409(models::Errors),
128    Status500(models::Errors),
129    UnknownValue(serde_json::Value),
130}
131
132
133/// This endpoint let user creates a label. 
134pub async fn create_label(configuration: &configuration::Configuration, params: CreateLabelParams) -> Result<(), Error<CreateLabelError>> {
135
136    let uri_str = format!("{}/labels", configuration.base_path);
137    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139    if let Some(ref user_agent) = configuration.user_agent {
140        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141    }
142    if let Some(param_value) = params.x_request_id {
143        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
144    }
145    if let Some(ref auth_conf) = configuration.basic_auth {
146        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
147    };
148    req_builder = req_builder.json(&params.label);
149
150    let req = req_builder.build()?;
151    let resp = configuration.client.execute(req).await?;
152
153    let status = resp.status();
154
155    if !status.is_client_error() && !status.is_server_error() {
156        Ok(())
157    } else {
158        let content = resp.text().await?;
159        let entity: Option<CreateLabelError> = serde_json::from_str(&content).ok();
160        Err(Error::ResponseError(ResponseContent { status, content, entity }))
161    }
162}
163
164/// Delete the label specified by ID. 
165pub async fn delete_label(configuration: &configuration::Configuration, params: DeleteLabelParams) -> Result<(), Error<DeleteLabelError>> {
166
167    let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_id);
168    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
169
170    if let Some(ref user_agent) = configuration.user_agent {
171        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172    }
173    if let Some(param_value) = params.x_request_id {
174        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
175    }
176    if let Some(ref auth_conf) = configuration.basic_auth {
177        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
178    };
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<DeleteLabelError> = serde_json::from_str(&content).ok();
190        Err(Error::ResponseError(ResponseContent { status, content, entity }))
191    }
192}
193
194/// This endpoint let user get the label by specific ID. 
195pub async fn get_label_by_id(configuration: &configuration::Configuration, params: GetLabelByIdParams) -> Result<models::Label, Error<GetLabelByIdError>> {
196
197    let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_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::Label`"))),
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::Label`")))),
227        }
228    } else {
229        let content = resp.text().await?;
230        let entity: Option<GetLabelByIdError> = serde_json::from_str(&content).ok();
231        Err(Error::ResponseError(ResponseContent { status, content, entity }))
232    }
233}
234
235/// This endpoint let user list labels by name, scope and project_id 
236pub async fn list_labels(configuration: &configuration::Configuration, params: ListLabelsParams) -> Result<Vec<models::Label>, Error<ListLabelsError>> {
237
238    let uri_str = format!("{}/labels", 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 param_value) = params.name {
254        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
255    }
256    if let Some(ref param_value) = params.scope {
257        req_builder = req_builder.query(&[("scope", &param_value.to_string())]);
258    }
259    if let Some(ref param_value) = params.project_id {
260        req_builder = req_builder.query(&[("project_id", &param_value.to_string())]);
261    }
262    if let Some(ref user_agent) = configuration.user_agent {
263        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264    }
265    if let Some(param_value) = params.x_request_id {
266        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
267    }
268    if let Some(ref auth_conf) = configuration.basic_auth {
269        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
270    };
271
272    let req = req_builder.build()?;
273    let resp = configuration.client.execute(req).await?;
274
275    let status = resp.status();
276    let content_type = resp
277        .headers()
278        .get("content-type")
279        .and_then(|v| v.to_str().ok())
280        .unwrap_or("application/octet-stream");
281    let content_type = super::ContentType::from(content_type);
282
283    if !status.is_client_error() && !status.is_server_error() {
284        let content = resp.text().await?;
285        match content_type {
286            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
287            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Label&gt;`"))),
288            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::Label&gt;`")))),
289        }
290    } else {
291        let content = resp.text().await?;
292        let entity: Option<ListLabelsError> = serde_json::from_str(&content).ok();
293        Err(Error::ResponseError(ResponseContent { status, content, entity }))
294    }
295}
296
297/// This endpoint let user update label properties. 
298pub async fn update_label(configuration: &configuration::Configuration, params: UpdateLabelParams) -> Result<(), Error<UpdateLabelError>> {
299
300    let uri_str = format!("{}/labels/{label_id}", configuration.base_path, label_id=params.label_id);
301    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
302
303    if let Some(ref user_agent) = configuration.user_agent {
304        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305    }
306    if let Some(param_value) = params.x_request_id {
307        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
308    }
309    if let Some(ref auth_conf) = configuration.basic_auth {
310        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
311    };
312    req_builder = req_builder.json(&params.label);
313
314    let req = req_builder.build()?;
315    let resp = configuration.client.execute(req).await?;
316
317    let status = resp.status();
318
319    if !status.is_client_error() && !status.is_server_error() {
320        Ok(())
321    } else {
322        let content = resp.text().await?;
323        let entity: Option<UpdateLabelError> = serde_json::from_str(&content).ok();
324        Err(Error::ResponseError(ResponseContent { status, content, entity }))
325    }
326}
327