harbor_api/apis/
jobservice_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 [`action_get_job_log`]
18#[derive(Clone, Debug)]
19pub struct ActionGetJobLogParams {
20    /// The id of the job.
21    pub job_id: String,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`action_pending_jobs`]
27#[derive(Clone, Debug)]
28pub struct ActionPendingJobsParams {
29    /// The type of the job. 'all' stands for all job types
30    pub job_type: String,
31    pub action_request: models::ActionRequest,
32    /// An unique ID for the request
33    pub x_request_id: Option<String>
34}
35
36/// struct for passing parameters to the method [`get_worker_pools`]
37#[derive(Clone, Debug)]
38pub struct GetWorkerPoolsParams {
39    /// An unique ID for the request
40    pub x_request_id: Option<String>
41}
42
43/// struct for passing parameters to the method [`get_workers`]
44#[derive(Clone, Debug)]
45pub struct GetWorkersParams {
46    /// The name of the pool. 'all' stands for all pools
47    pub pool_id: String,
48    /// An unique ID for the request
49    pub x_request_id: Option<String>
50}
51
52/// struct for passing parameters to the method [`list_job_queues`]
53#[derive(Clone, Debug)]
54pub struct ListJobQueuesParams {
55    /// An unique ID for the request
56    pub x_request_id: Option<String>
57}
58
59/// struct for passing parameters to the method [`stop_running_job`]
60#[derive(Clone, Debug)]
61pub struct StopRunningJobParams {
62    /// The id of the job.
63    pub job_id: String,
64    /// An unique ID for the request
65    pub x_request_id: Option<String>
66}
67
68
69/// struct for typed errors of method [`action_get_job_log`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ActionGetJobLogError {
73    Status401(models::Errors),
74    Status403(models::Errors),
75    Status404(models::Errors),
76    Status500(models::Errors),
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`action_pending_jobs`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum ActionPendingJobsError {
84    Status401(models::Errors),
85    Status403(models::Errors),
86    Status404(models::Errors),
87    Status422(models::Errors),
88    Status500(models::Errors),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`get_worker_pools`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum GetWorkerPoolsError {
96    Status401(models::Errors),
97    Status403(models::Errors),
98    Status500(models::Errors),
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`get_workers`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum GetWorkersError {
106    Status401(models::Errors),
107    Status403(models::Errors),
108    Status404(models::Errors),
109    Status500(models::Errors),
110    UnknownValue(serde_json::Value),
111}
112
113/// struct for typed errors of method [`list_job_queues`]
114#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum ListJobQueuesError {
117    Status401(models::Errors),
118    Status403(models::Errors),
119    Status404(models::Errors),
120    Status500(models::Errors),
121    UnknownValue(serde_json::Value),
122}
123
124/// struct for typed errors of method [`stop_running_job`]
125#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum StopRunningJobError {
128    Status401(models::Errors),
129    Status403(models::Errors),
130    Status404(models::Errors),
131    Status500(models::Errors),
132    UnknownValue(serde_json::Value),
133}
134
135
136/// Get job log by job id, it is only used by administrator
137pub async fn action_get_job_log(configuration: &configuration::Configuration, params: ActionGetJobLogParams) -> Result<String, Error<ActionGetJobLogError>> {
138
139    let uri_str = format!("{}/jobservice/jobs/{job_id}/log", configuration.base_path, job_id=crate::apis::urlencode(params.job_id));
140    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
141
142    if let Some(ref user_agent) = configuration.user_agent {
143        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
144    }
145    if let Some(param_value) = params.x_request_id {
146        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
147    }
148    if let Some(ref auth_conf) = configuration.basic_auth {
149        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150    };
151
152    let req = req_builder.build()?;
153    let resp = configuration.client.execute(req).await?;
154
155    let status = resp.status();
156    let content_type = resp
157        .headers()
158        .get("content-type")
159        .and_then(|v| v.to_str().ok())
160        .unwrap_or("application/octet-stream");
161    let content_type = super::ContentType::from(content_type);
162
163    if !status.is_client_error() && !status.is_server_error() {
164        let content = resp.text().await?;
165        match content_type {
166            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167            ContentType::Text => return Ok(content),
168            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`")))),
169        }
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<ActionGetJobLogError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent { status, content, entity }))
174    }
175}
176
177/// stop and clean, pause, resume pending jobs in the queue
178pub async fn action_pending_jobs(configuration: &configuration::Configuration, params: ActionPendingJobsParams) -> Result<(), Error<ActionPendingJobsError>> {
179
180    let uri_str = format!("{}/jobservice/queues/{job_type}", configuration.base_path, job_type=crate::apis::urlencode(params.job_type));
181    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
182
183    if let Some(ref user_agent) = configuration.user_agent {
184        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185    }
186    if let Some(param_value) = params.x_request_id {
187        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
188    }
189    if let Some(ref auth_conf) = configuration.basic_auth {
190        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
191    };
192    req_builder = req_builder.json(&params.action_request);
193
194    let req = req_builder.build()?;
195    let resp = configuration.client.execute(req).await?;
196
197    let status = resp.status();
198
199    if !status.is_client_error() && !status.is_server_error() {
200        Ok(())
201    } else {
202        let content = resp.text().await?;
203        let entity: Option<ActionPendingJobsError> = serde_json::from_str(&content).ok();
204        Err(Error::ResponseError(ResponseContent { status, content, entity }))
205    }
206}
207
208/// Get worker pools
209pub async fn get_worker_pools(configuration: &configuration::Configuration, params: GetWorkerPoolsParams) -> Result<Vec<models::WorkerPool>, Error<GetWorkerPoolsError>> {
210
211    let uri_str = format!("{}/jobservice/pools", configuration.base_path);
212    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
213
214    if let Some(ref user_agent) = configuration.user_agent {
215        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
216    }
217    if let Some(param_value) = params.x_request_id {
218        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
219    }
220    if let Some(ref auth_conf) = configuration.basic_auth {
221        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
222    };
223
224    let req = req_builder.build()?;
225    let resp = configuration.client.execute(req).await?;
226
227    let status = resp.status();
228    let content_type = resp
229        .headers()
230        .get("content-type")
231        .and_then(|v| v.to_str().ok())
232        .unwrap_or("application/octet-stream");
233    let content_type = super::ContentType::from(content_type);
234
235    if !status.is_client_error() && !status.is_server_error() {
236        let content = resp.text().await?;
237        match content_type {
238            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
239            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::WorkerPool&gt;`"))),
240            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::WorkerPool&gt;`")))),
241        }
242    } else {
243        let content = resp.text().await?;
244        let entity: Option<GetWorkerPoolsError> = serde_json::from_str(&content).ok();
245        Err(Error::ResponseError(ResponseContent { status, content, entity }))
246    }
247}
248
249/// Get workers in current pool
250pub async fn get_workers(configuration: &configuration::Configuration, params: GetWorkersParams) -> Result<Vec<models::Worker>, Error<GetWorkersError>> {
251
252    let uri_str = format!("{}/jobservice/pools/{pool_id}/workers", configuration.base_path, pool_id=crate::apis::urlencode(params.pool_id));
253    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
254
255    if let Some(ref user_agent) = configuration.user_agent {
256        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
257    }
258    if let Some(param_value) = params.x_request_id {
259        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
260    }
261    if let Some(ref auth_conf) = configuration.basic_auth {
262        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
263    };
264
265    let req = req_builder.build()?;
266    let resp = configuration.client.execute(req).await?;
267
268    let status = resp.status();
269    let content_type = resp
270        .headers()
271        .get("content-type")
272        .and_then(|v| v.to_str().ok())
273        .unwrap_or("application/octet-stream");
274    let content_type = super::ContentType::from(content_type);
275
276    if !status.is_client_error() && !status.is_server_error() {
277        let content = resp.text().await?;
278        match content_type {
279            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Worker&gt;`"))),
281            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::Worker&gt;`")))),
282        }
283    } else {
284        let content = resp.text().await?;
285        let entity: Option<GetWorkersError> = serde_json::from_str(&content).ok();
286        Err(Error::ResponseError(ResponseContent { status, content, entity }))
287    }
288}
289
290/// list job queue
291pub async fn list_job_queues(configuration: &configuration::Configuration, params: ListJobQueuesParams) -> Result<Vec<models::JobQueue>, Error<ListJobQueuesError>> {
292
293    let uri_str = format!("{}/jobservice/queues", configuration.base_path);
294    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
295
296    if let Some(ref user_agent) = configuration.user_agent {
297        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
298    }
299    if let Some(param_value) = params.x_request_id {
300        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
301    }
302    if let Some(ref auth_conf) = configuration.basic_auth {
303        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
304    };
305
306    let req = req_builder.build()?;
307    let resp = configuration.client.execute(req).await?;
308
309    let status = resp.status();
310    let content_type = resp
311        .headers()
312        .get("content-type")
313        .and_then(|v| v.to_str().ok())
314        .unwrap_or("application/octet-stream");
315    let content_type = super::ContentType::from(content_type);
316
317    if !status.is_client_error() && !status.is_server_error() {
318        let content = resp.text().await?;
319        match content_type {
320            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
321            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::JobQueue&gt;`"))),
322            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::JobQueue&gt;`")))),
323        }
324    } else {
325        let content = resp.text().await?;
326        let entity: Option<ListJobQueuesError> = serde_json::from_str(&content).ok();
327        Err(Error::ResponseError(ResponseContent { status, content, entity }))
328    }
329}
330
331/// Stop running job
332pub async fn stop_running_job(configuration: &configuration::Configuration, params: StopRunningJobParams) -> Result<(), Error<StopRunningJobError>> {
333
334    let uri_str = format!("{}/jobservice/jobs/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(params.job_id));
335    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
336
337    if let Some(ref user_agent) = configuration.user_agent {
338        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
339    }
340    if let Some(param_value) = params.x_request_id {
341        req_builder = req_builder.header("X-Request-Id", 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
347    let req = req_builder.build()?;
348    let resp = configuration.client.execute(req).await?;
349
350    let status = resp.status();
351
352    if !status.is_client_error() && !status.is_server_error() {
353        Ok(())
354    } else {
355        let content = resp.text().await?;
356        let entity: Option<StopRunningJobError> = serde_json::from_str(&content).ok();
357        Err(Error::ResponseError(ResponseContent { status, content, entity }))
358    }
359}
360