harbor_api/apis/
schedule_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct GetSchedulePausedParams {
20 pub job_type: String,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct ListSchedulesParams {
29 pub x_request_id: Option<String>,
31 pub page: Option<i64>,
33 pub page_size: Option<i64>
35}
36
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetSchedulePausedError {
42 Status401(models::Errors),
43 Status403(models::Errors),
44 Status404(models::Errors),
45 Status500(models::Errors),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum ListSchedulesError {
53 Status401(models::Errors),
54 Status403(models::Errors),
55 Status404(models::Errors),
56 Status500(models::Errors),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn get_schedule_paused(configuration: &configuration::Configuration, params: GetSchedulePausedParams) -> Result<models::SchedulerStatus, Error<GetSchedulePausedError>> {
63
64 let uri_str = format!("{}/schedules/{job_type}/paused", configuration.base_path, job_type=crate::apis::urlencode(params.job_type));
65 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67 if let Some(ref user_agent) = configuration.user_agent {
68 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69 }
70 if let Some(param_value) = params.x_request_id {
71 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
72 }
73 if let Some(ref auth_conf) = configuration.basic_auth {
74 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
75 };
76
77 let req = req_builder.build()?;
78 let resp = configuration.client.execute(req).await?;
79
80 let status = resp.status();
81 let content_type = resp
82 .headers()
83 .get("content-type")
84 .and_then(|v| v.to_str().ok())
85 .unwrap_or("application/octet-stream");
86 let content_type = super::ContentType::from(content_type);
87
88 if !status.is_client_error() && !status.is_server_error() {
89 let content = resp.text().await?;
90 match content_type {
91 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
92 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchedulerStatus`"))),
93 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::SchedulerStatus`")))),
94 }
95 } else {
96 let content = resp.text().await?;
97 let entity: Option<GetSchedulePausedError> = serde_json::from_str(&content).ok();
98 Err(Error::ResponseError(ResponseContent { status, content, entity }))
99 }
100}
101
102pub async fn list_schedules(configuration: &configuration::Configuration, params: ListSchedulesParams) -> Result<Vec<models::ScheduleTask>, Error<ListSchedulesError>> {
104
105 let uri_str = format!("{}/schedules", configuration.base_path);
106 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
107
108 if let Some(ref param_value) = params.page {
109 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
110 }
111 if let Some(ref param_value) = params.page_size {
112 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
113 }
114 if let Some(ref user_agent) = configuration.user_agent {
115 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116 }
117 if let Some(param_value) = params.x_request_id {
118 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
119 }
120 if let Some(ref auth_conf) = configuration.basic_auth {
121 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
122 };
123
124 let req = req_builder.build()?;
125 let resp = configuration.client.execute(req).await?;
126
127 let status = resp.status();
128 let content_type = resp
129 .headers()
130 .get("content-type")
131 .and_then(|v| v.to_str().ok())
132 .unwrap_or("application/octet-stream");
133 let content_type = super::ContentType::from(content_type);
134
135 if !status.is_client_error() && !status.is_server_error() {
136 let content = resp.text().await?;
137 match content_type {
138 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ScheduleTask>`"))),
140 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<models::ScheduleTask>`")))),
141 }
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<ListSchedulesError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent { status, content, entity }))
146 }
147}
148