harbor_api/apis/
robotv1_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_robot_v1`]
18#[derive(Clone, Debug)]
19pub struct CreateRobotV1Params {
20    /// The name or id of the project
21    pub project_name_or_id: String,
22    /// The JSON object of a robot account.
23    pub robot: models::RobotCreateV1,
24    /// An unique ID for the request
25    pub x_request_id: Option<String>,
26    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
27    pub x_is_resource_name: Option<bool>
28}
29
30/// struct for passing parameters to the method [`delete_robot_v1`]
31#[derive(Clone, Debug)]
32pub struct DeleteRobotV1Params {
33    /// The name or id of the project
34    pub project_name_or_id: String,
35    /// Robot ID
36    pub robot_id: i32,
37    /// An unique ID for the request
38    pub x_request_id: Option<String>,
39    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
40    pub x_is_resource_name: Option<bool>
41}
42
43/// struct for passing parameters to the method [`get_robot_by_idv1`]
44#[derive(Clone, Debug)]
45pub struct GetRobotByIdv1Params {
46    /// The name or id of the project
47    pub project_name_or_id: String,
48    /// Robot ID
49    pub robot_id: i32,
50    /// An unique ID for the request
51    pub x_request_id: Option<String>,
52    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
53    pub x_is_resource_name: Option<bool>
54}
55
56/// struct for passing parameters to the method [`list_robot_v1`]
57#[derive(Clone, Debug)]
58pub struct ListRobotV1Params {
59    /// The name or id of the project
60    pub project_name_or_id: String,
61    /// An unique ID for the request
62    pub x_request_id: Option<String>,
63    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
64    pub x_is_resource_name: Option<bool>,
65    /// The page number
66    pub page: Option<i64>,
67    /// The size of per page
68    pub page_size: Option<i64>,
69    /// 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]
70    pub q: Option<String>,
71    /// 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\"
72    pub sort: Option<String>
73}
74
75/// struct for passing parameters to the method [`update_robot_v1`]
76#[derive(Clone, Debug)]
77pub struct UpdateRobotV1Params {
78    /// The name or id of the project
79    pub project_name_or_id: String,
80    /// Robot ID
81    pub robot_id: i32,
82    /// The JSON object of a robot account.
83    pub robot: models::Robot,
84    /// An unique ID for the request
85    pub x_request_id: Option<String>,
86    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
87    pub x_is_resource_name: Option<bool>
88}
89
90
91/// struct for typed errors of method [`create_robot_v1`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum CreateRobotV1Error {
95    Status400(models::Errors),
96    Status401(models::Errors),
97    Status403(models::Errors),
98    Status404(models::Errors),
99    Status500(models::Errors),
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`delete_robot_v1`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum DeleteRobotV1Error {
107    Status400(models::Errors),
108    Status401(models::Errors),
109    Status403(models::Errors),
110    Status404(models::Errors),
111    Status500(models::Errors),
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`get_robot_by_idv1`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum GetRobotByIdv1Error {
119    Status401(models::Errors),
120    Status403(models::Errors),
121    Status404(models::Errors),
122    Status500(models::Errors),
123    UnknownValue(serde_json::Value),
124}
125
126/// struct for typed errors of method [`list_robot_v1`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum ListRobotV1Error {
130    Status400(models::Errors),
131    Status404(models::Errors),
132    Status500(models::Errors),
133    UnknownValue(serde_json::Value),
134}
135
136/// struct for typed errors of method [`update_robot_v1`]
137#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(untagged)]
139pub enum UpdateRobotV1Error {
140    Status400(models::Errors),
141    Status401(models::Errors),
142    Status403(models::Errors),
143    Status404(models::Errors),
144    Status409(models::Errors),
145    Status500(models::Errors),
146    UnknownValue(serde_json::Value),
147}
148
149
150/// Create a robot account
151pub async fn create_robot_v1(configuration: &configuration::Configuration, params: CreateRobotV1Params) -> Result<models::RobotCreated, Error<CreateRobotV1Error>> {
152
153    let uri_str = format!("{}/projects/{project_name_or_id}/robots", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
154    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
155
156    if let Some(ref user_agent) = configuration.user_agent {
157        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158    }
159    if let Some(param_value) = params.x_request_id {
160        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
161    }
162    if let Some(param_value) = params.x_is_resource_name {
163        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
164    }
165    if let Some(ref auth_conf) = configuration.basic_auth {
166        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
167    };
168    req_builder = req_builder.json(&params.robot);
169
170    let req = req_builder.build()?;
171    let resp = configuration.client.execute(req).await?;
172
173    let status = resp.status();
174    let content_type = resp
175        .headers()
176        .get("content-type")
177        .and_then(|v| v.to_str().ok())
178        .unwrap_or("application/octet-stream");
179    let content_type = super::ContentType::from(content_type);
180
181    if !status.is_client_error() && !status.is_server_error() {
182        let content = resp.text().await?;
183        match content_type {
184            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
185            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RobotCreated`"))),
186            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::RobotCreated`")))),
187        }
188    } else {
189        let content = resp.text().await?;
190        let entity: Option<CreateRobotV1Error> = serde_json::from_str(&content).ok();
191        Err(Error::ResponseError(ResponseContent { status, content, entity }))
192    }
193}
194
195/// This endpoint deletes specific robot account information by robot ID.
196pub async fn delete_robot_v1(configuration: &configuration::Configuration, params: DeleteRobotV1Params) -> Result<(), Error<DeleteRobotV1Error>> {
197
198    let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), robot_id=params.robot_id);
199    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
200
201    if let Some(ref user_agent) = configuration.user_agent {
202        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
203    }
204    if let Some(param_value) = params.x_request_id {
205        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
206    }
207    if let Some(param_value) = params.x_is_resource_name {
208        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
209    }
210    if let Some(ref auth_conf) = configuration.basic_auth {
211        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
212    };
213
214    let req = req_builder.build()?;
215    let resp = configuration.client.execute(req).await?;
216
217    let status = resp.status();
218
219    if !status.is_client_error() && !status.is_server_error() {
220        Ok(())
221    } else {
222        let content = resp.text().await?;
223        let entity: Option<DeleteRobotV1Error> = serde_json::from_str(&content).ok();
224        Err(Error::ResponseError(ResponseContent { status, content, entity }))
225    }
226}
227
228/// This endpoint returns specific robot account information by robot ID.
229pub async fn get_robot_by_idv1(configuration: &configuration::Configuration, params: GetRobotByIdv1Params) -> Result<models::Robot, Error<GetRobotByIdv1Error>> {
230
231    let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), robot_id=params.robot_id);
232    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
233
234    if let Some(ref user_agent) = configuration.user_agent {
235        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236    }
237    if let Some(param_value) = params.x_request_id {
238        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
239    }
240    if let Some(param_value) = params.x_is_resource_name {
241        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
242    }
243    if let Some(ref auth_conf) = configuration.basic_auth {
244        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
245    };
246
247    let req = req_builder.build()?;
248    let resp = configuration.client.execute(req).await?;
249
250    let status = resp.status();
251    let content_type = resp
252        .headers()
253        .get("content-type")
254        .and_then(|v| v.to_str().ok())
255        .unwrap_or("application/octet-stream");
256    let content_type = super::ContentType::from(content_type);
257
258    if !status.is_client_error() && !status.is_server_error() {
259        let content = resp.text().await?;
260        match content_type {
261            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
262            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Robot`"))),
263            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::Robot`")))),
264        }
265    } else {
266        let content = resp.text().await?;
267        let entity: Option<GetRobotByIdv1Error> = serde_json::from_str(&content).ok();
268        Err(Error::ResponseError(ResponseContent { status, content, entity }))
269    }
270}
271
272/// Get all robot accounts of specified project
273pub async fn list_robot_v1(configuration: &configuration::Configuration, params: ListRobotV1Params) -> Result<Vec<models::Robot>, Error<ListRobotV1Error>> {
274
275    let uri_str = format!("{}/projects/{project_name_or_id}/robots", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
276    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
277
278    if let Some(ref param_value) = params.page {
279        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
280    }
281    if let Some(ref param_value) = params.page_size {
282        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
283    }
284    if let Some(ref param_value) = params.q {
285        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
286    }
287    if let Some(ref param_value) = params.sort {
288        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
289    }
290    if let Some(ref user_agent) = configuration.user_agent {
291        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
292    }
293    if let Some(param_value) = params.x_request_id {
294        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
295    }
296    if let Some(param_value) = params.x_is_resource_name {
297        req_builder = req_builder.header("X-Is-Resource-Name", 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 Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Robot&gt;`"))),
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 `Vec&lt;models::Robot&gt;`")))),
320        }
321    } else {
322        let content = resp.text().await?;
323        let entity: Option<ListRobotV1Error> = serde_json::from_str(&content).ok();
324        Err(Error::ResponseError(ResponseContent { status, content, entity }))
325    }
326}
327
328/// Used to disable/enable a specified robot account.
329pub async fn update_robot_v1(configuration: &configuration::Configuration, params: UpdateRobotV1Params) -> Result<(), Error<UpdateRobotV1Error>> {
330
331    let uri_str = format!("{}/projects/{project_name_or_id}/robots/{robot_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), robot_id=params.robot_id);
332    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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(param_value) = params.x_is_resource_name {
341        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
342    }
343    if let Some(ref auth_conf) = configuration.basic_auth {
344        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345    };
346    req_builder = req_builder.json(&params.robot);
347
348    let req = req_builder.build()?;
349    let resp = configuration.client.execute(req).await?;
350
351    let status = resp.status();
352
353    if !status.is_client_error() && !status.is_server_error() {
354        Ok(())
355    } else {
356        let content = resp.text().await?;
357        let entity: Option<UpdateRobotV1Error> = serde_json::from_str(&content).ok();
358        Err(Error::ResponseError(ResponseContent { status, content, entity }))
359    }
360}
361