harbor_api/apis/
robot_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`]
18#[derive(Clone, Debug)]
19pub struct CreateRobotParams {
20    /// The JSON object of a robot account.
21    pub robot: models::RobotCreate,
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_robot`]
27#[derive(Clone, Debug)]
28pub struct DeleteRobotParams {
29    /// Robot ID
30    pub robot_id: i32,
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_robot_by_id`]
36#[derive(Clone, Debug)]
37pub struct GetRobotByIdParams {
38    /// Robot ID
39    pub robot_id: i32,
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_robot`]
45#[derive(Clone, Debug)]
46pub struct ListRobotParams {
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}
58
59/// struct for passing parameters to the method [`refresh_sec`]
60#[derive(Clone, Debug)]
61pub struct RefreshSecParams {
62    /// Robot ID
63    pub robot_id: i32,
64    /// The JSON object of a robot account.
65    pub robot_sec: models::RobotSec,
66    /// An unique ID for the request
67    pub x_request_id: Option<String>
68}
69
70/// struct for passing parameters to the method [`update_robot`]
71#[derive(Clone, Debug)]
72pub struct UpdateRobotParams {
73    /// Robot ID
74    pub robot_id: i32,
75    /// The JSON object of a robot account.
76    pub robot: models::Robot,
77    /// An unique ID for the request
78    pub x_request_id: Option<String>
79}
80
81
82/// struct for typed errors of method [`create_robot`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateRobotError {
86    Status400(models::Errors),
87    Status401(models::Errors),
88    Status403(models::Errors),
89    Status404(models::Errors),
90    Status500(models::Errors),
91    UnknownValue(serde_json::Value),
92}
93
94/// struct for typed errors of method [`delete_robot`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum DeleteRobotError {
98    Status400(models::Errors),
99    Status401(models::Errors),
100    Status403(models::Errors),
101    Status404(models::Errors),
102    Status500(models::Errors),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`get_robot_by_id`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetRobotByIdError {
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 [`list_robot`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum ListRobotError {
121    Status400(models::Errors),
122    Status404(models::Errors),
123    Status500(models::Errors),
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`refresh_sec`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum RefreshSecError {
131    Status400(models::Errors),
132    Status401(models::Errors),
133    Status403(models::Errors),
134    Status404(models::Errors),
135    Status500(models::Errors),
136    UnknownValue(serde_json::Value),
137}
138
139/// struct for typed errors of method [`update_robot`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum UpdateRobotError {
143    Status400(models::Errors),
144    Status401(models::Errors),
145    Status403(models::Errors),
146    Status404(models::Errors),
147    Status409(models::Errors),
148    Status500(models::Errors),
149    UnknownValue(serde_json::Value),
150}
151
152
153/// Create a robot account
154pub async fn create_robot(configuration: &configuration::Configuration, params: CreateRobotParams) -> Result<models::RobotCreated, Error<CreateRobotError>> {
155
156    let uri_str = format!("{}/robots", configuration.base_path);
157    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(param_value) = params.x_request_id {
163        req_builder = req_builder.header("X-Request-Id", 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<CreateRobotError> = 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(configuration: &configuration::Configuration, params: DeleteRobotParams) -> Result<(), Error<DeleteRobotError>> {
197
198    let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, 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(ref auth_conf) = configuration.basic_auth {
208        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
209    };
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215
216    if !status.is_client_error() && !status.is_server_error() {
217        Ok(())
218    } else {
219        let content = resp.text().await?;
220        let entity: Option<DeleteRobotError> = serde_json::from_str(&content).ok();
221        Err(Error::ResponseError(ResponseContent { status, content, entity }))
222    }
223}
224
225/// This endpoint returns specific robot account information by robot ID.
226pub async fn get_robot_by_id(configuration: &configuration::Configuration, params: GetRobotByIdParams) -> Result<models::Robot, Error<GetRobotByIdError>> {
227
228    let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
229    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231    if let Some(ref user_agent) = configuration.user_agent {
232        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233    }
234    if let Some(param_value) = params.x_request_id {
235        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
236    }
237    if let Some(ref auth_conf) = configuration.basic_auth {
238        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
239    };
240
241    let req = req_builder.build()?;
242    let resp = configuration.client.execute(req).await?;
243
244    let status = resp.status();
245    let content_type = resp
246        .headers()
247        .get("content-type")
248        .and_then(|v| v.to_str().ok())
249        .unwrap_or("application/octet-stream");
250    let content_type = super::ContentType::from(content_type);
251
252    if !status.is_client_error() && !status.is_server_error() {
253        let content = resp.text().await?;
254        match content_type {
255            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Robot`"))),
257            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`")))),
258        }
259    } else {
260        let content = resp.text().await?;
261        let entity: Option<GetRobotByIdError> = serde_json::from_str(&content).ok();
262        Err(Error::ResponseError(ResponseContent { status, content, entity }))
263    }
264}
265
266/// List the robot accounts with the specified level and project.
267pub async fn list_robot(configuration: &configuration::Configuration, params: ListRobotParams) -> Result<Vec<models::Robot>, Error<ListRobotError>> {
268
269    let uri_str = format!("{}/robots", configuration.base_path);
270    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
271
272    if let Some(ref param_value) = params.q {
273        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
274    }
275    if let Some(ref param_value) = params.sort {
276        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
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 user_agent) = configuration.user_agent {
285        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
286    }
287    if let Some(param_value) = params.x_request_id {
288        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
289    }
290    if let Some(ref auth_conf) = configuration.basic_auth {
291        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
292    };
293
294    let req = req_builder.build()?;
295    let resp = configuration.client.execute(req).await?;
296
297    let status = resp.status();
298    let content_type = resp
299        .headers()
300        .get("content-type")
301        .and_then(|v| v.to_str().ok())
302        .unwrap_or("application/octet-stream");
303    let content_type = super::ContentType::from(content_type);
304
305    if !status.is_client_error() && !status.is_server_error() {
306        let content = resp.text().await?;
307        match content_type {
308            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
309            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;`"))),
310            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;`")))),
311        }
312    } else {
313        let content = resp.text().await?;
314        let entity: Option<ListRobotError> = serde_json::from_str(&content).ok();
315        Err(Error::ResponseError(ResponseContent { status, content, entity }))
316    }
317}
318
319/// Refresh the robot secret
320pub async fn refresh_sec(configuration: &configuration::Configuration, params: RefreshSecParams) -> Result<models::RobotSec, Error<RefreshSecError>> {
321
322    let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
323    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &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.robot_sec);
335
336    let req = req_builder.build()?;
337    let resp = configuration.client.execute(req).await?;
338
339    let status = resp.status();
340    let content_type = resp
341        .headers()
342        .get("content-type")
343        .and_then(|v| v.to_str().ok())
344        .unwrap_or("application/octet-stream");
345    let content_type = super::ContentType::from(content_type);
346
347    if !status.is_client_error() && !status.is_server_error() {
348        let content = resp.text().await?;
349        match content_type {
350            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
351            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RobotSec`"))),
352            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::RobotSec`")))),
353        }
354    } else {
355        let content = resp.text().await?;
356        let entity: Option<RefreshSecError> = serde_json::from_str(&content).ok();
357        Err(Error::ResponseError(ResponseContent { status, content, entity }))
358    }
359}
360
361/// This endpoint updates specific robot account information by robot ID.
362pub async fn update_robot(configuration: &configuration::Configuration, params: UpdateRobotParams) -> Result<(), Error<UpdateRobotError>> {
363
364    let uri_str = format!("{}/robots/{robot_id}", configuration.base_path, robot_id=params.robot_id);
365    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
366
367    if let Some(ref user_agent) = configuration.user_agent {
368        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
369    }
370    if let Some(param_value) = params.x_request_id {
371        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
372    }
373    if let Some(ref auth_conf) = configuration.basic_auth {
374        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
375    };
376    req_builder = req_builder.json(&params.robot);
377
378    let req = req_builder.build()?;
379    let resp = configuration.client.execute(req).await?;
380
381    let status = resp.status();
382
383    if !status.is_client_error() && !status.is_server_error() {
384        Ok(())
385    } else {
386        let content = resp.text().await?;
387        let entity: Option<UpdateRobotError> = serde_json::from_str(&content).ok();
388        Err(Error::ResponseError(ResponseContent { status, content, entity }))
389    }
390}
391