harbor_api/apis/
quota_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 GetQuotaParams {
20 pub id: i32,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct ListQuotasParams {
29 pub x_request_id: Option<String>,
31 pub page: Option<i64>,
33 pub page_size: Option<i64>,
35 pub reference: Option<String>,
37 pub reference_id: Option<String>,
39 pub sort: Option<String>
41}
42
43#[derive(Clone, Debug)]
45pub struct UpdateQuotaParams {
46 pub id: i32,
48 pub hard: models::QuotaUpdateReq,
50 pub x_request_id: Option<String>
52}
53
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum GetQuotaError {
59 Status401(models::Errors),
60 Status403(models::Errors),
61 Status404(models::Errors),
62 Status500(models::Errors),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListQuotasError {
70 Status401(models::Errors),
71 Status403(models::Errors),
72 Status500(models::Errors),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum UpdateQuotaError {
80 Status400(models::Errors),
81 Status401(models::Errors),
82 Status403(models::Errors),
83 Status404(models::Errors),
84 Status500(models::Errors),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn get_quota(configuration: &configuration::Configuration, params: GetQuotaParams) -> Result<models::Quota, Error<GetQuotaError>> {
91
92 let uri_str = format!("{}/quotas/{id}", configuration.base_path, id=params.id);
93 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
94
95 if let Some(ref user_agent) = configuration.user_agent {
96 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97 }
98 if let Some(param_value) = params.x_request_id {
99 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
100 }
101 if let Some(ref auth_conf) = configuration.basic_auth {
102 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
103 };
104
105 let req = req_builder.build()?;
106 let resp = configuration.client.execute(req).await?;
107
108 let status = resp.status();
109 let content_type = resp
110 .headers()
111 .get("content-type")
112 .and_then(|v| v.to_str().ok())
113 .unwrap_or("application/octet-stream");
114 let content_type = super::ContentType::from(content_type);
115
116 if !status.is_client_error() && !status.is_server_error() {
117 let content = resp.text().await?;
118 match content_type {
119 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Quota`"))),
121 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::Quota`")))),
122 }
123 } else {
124 let content = resp.text().await?;
125 let entity: Option<GetQuotaError> = serde_json::from_str(&content).ok();
126 Err(Error::ResponseError(ResponseContent { status, content, entity }))
127 }
128}
129
130pub async fn list_quotas(configuration: &configuration::Configuration, params: ListQuotasParams) -> Result<Vec<models::Quota>, Error<ListQuotasError>> {
132
133 let uri_str = format!("{}/quotas", configuration.base_path);
134 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
135
136 if let Some(ref param_value) = params.page {
137 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
138 }
139 if let Some(ref param_value) = params.page_size {
140 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
141 }
142 if let Some(ref param_value) = params.reference {
143 req_builder = req_builder.query(&[("reference", ¶m_value.to_string())]);
144 }
145 if let Some(ref param_value) = params.reference_id {
146 req_builder = req_builder.query(&[("reference_id", ¶m_value.to_string())]);
147 }
148 if let Some(ref param_value) = params.sort {
149 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
150 }
151 if let Some(ref user_agent) = configuration.user_agent {
152 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153 }
154 if let Some(param_value) = params.x_request_id {
155 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
156 }
157 if let Some(ref auth_conf) = configuration.basic_auth {
158 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
159 };
160
161 let req = req_builder.build()?;
162 let resp = configuration.client.execute(req).await?;
163
164 let status = resp.status();
165 let content_type = resp
166 .headers()
167 .get("content-type")
168 .and_then(|v| v.to_str().ok())
169 .unwrap_or("application/octet-stream");
170 let content_type = super::ContentType::from(content_type);
171
172 if !status.is_client_error() && !status.is_server_error() {
173 let content = resp.text().await?;
174 match content_type {
175 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Quota>`"))),
177 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::Quota>`")))),
178 }
179 } else {
180 let content = resp.text().await?;
181 let entity: Option<ListQuotasError> = serde_json::from_str(&content).ok();
182 Err(Error::ResponseError(ResponseContent { status, content, entity }))
183 }
184}
185
186pub async fn update_quota(configuration: &configuration::Configuration, params: UpdateQuotaParams) -> Result<(), Error<UpdateQuotaError>> {
188
189 let uri_str = format!("{}/quotas/{id}", configuration.base_path, id=params.id);
190 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
191
192 if let Some(ref user_agent) = configuration.user_agent {
193 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194 }
195 if let Some(param_value) = params.x_request_id {
196 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
197 }
198 if let Some(ref auth_conf) = configuration.basic_auth {
199 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200 };
201 req_builder = req_builder.json(¶ms.hard);
202
203 let req = req_builder.build()?;
204 let resp = configuration.client.execute(req).await?;
205
206 let status = resp.status();
207
208 if !status.is_client_error() && !status.is_server_error() {
209 Ok(())
210 } else {
211 let content = resp.text().await?;
212 let entity: Option<UpdateQuotaError> = serde_json::from_str(&content).ok();
213 Err(Error::ResponseError(ResponseContent { status, content, entity }))
214 }
215}
216