harbor_api/apis/
quota_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 [`get_quota`]
18#[derive(Clone, Debug)]
19pub struct GetQuotaParams {
20    /// Quota ID
21    pub id: i32,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`list_quotas`]
27#[derive(Clone, Debug)]
28pub struct ListQuotasParams {
29    /// An unique ID for the request
30    pub x_request_id: Option<String>,
31    /// The page number
32    pub page: Option<i64>,
33    /// The size of per page
34    pub page_size: Option<i64>,
35    /// The reference type of quota.
36    pub reference: Option<String>,
37    /// The reference id of quota.
38    pub reference_id: Option<String>,
39    /// Sort method, valid values include: 'hard.resource_name', '-hard.resource_name', 'used.resource_name', '-used.resource_name'. Here '-' stands for descending order, resource_name should be the real resource name of the quota. 
40    pub sort: Option<String>
41}
42
43/// struct for passing parameters to the method [`update_quota`]
44#[derive(Clone, Debug)]
45pub struct UpdateQuotaParams {
46    /// Quota ID
47    pub id: i32,
48    /// The new hard limits for the quota
49    pub hard: models::QuotaUpdateReq,
50    /// An unique ID for the request
51    pub x_request_id: Option<String>
52}
53
54
55/// struct for typed errors of method [`get_quota`]
56#[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/// struct for typed errors of method [`list_quotas`]
67#[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/// struct for typed errors of method [`update_quota`]
77#[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
89/// Get the specified quota
90pub 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
130/// List quotas
131pub 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", &param_value.to_string())]);
138    }
139    if let Some(ref param_value) = params.page_size {
140        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
141    }
142    if let Some(ref param_value) = params.reference {
143        req_builder = req_builder.query(&[("reference", &param_value.to_string())]);
144    }
145    if let Some(ref param_value) = params.reference_id {
146        req_builder = req_builder.query(&[("reference_id", &param_value.to_string())]);
147    }
148    if let Some(ref param_value) = params.sort {
149        req_builder = req_builder.query(&[("sort", &param_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&lt;models::Quota&gt;`"))),
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&lt;models::Quota&gt;`")))),
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
186/// Update hard limits of the specified quota
187pub 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(&params.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