harbor_api/apis/
repository_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 [`delete_repository`]
18#[derive(Clone, Debug)]
19pub struct DeleteRepositoryParams {
20    /// The name of the project
21    pub project_name: String,
22    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
23    pub repository_name: String,
24    /// An unique ID for the request
25    pub x_request_id: Option<String>
26}
27
28/// struct for passing parameters to the method [`get_repository`]
29#[derive(Clone, Debug)]
30pub struct GetRepositoryParams {
31    /// The name of the project
32    pub project_name: String,
33    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
34    pub repository_name: String,
35    /// An unique ID for the request
36    pub x_request_id: Option<String>
37}
38
39/// struct for passing parameters to the method [`list_all_repositories`]
40#[derive(Clone, Debug)]
41pub struct ListAllRepositoriesParams {
42    /// An unique ID for the request
43    pub x_request_id: Option<String>,
44    /// 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]
45    pub q: Option<String>,
46    /// 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\"
47    pub sort: Option<String>,
48    /// The page number
49    pub page: Option<i64>,
50    /// The size of per page
51    pub page_size: Option<i64>
52}
53
54/// struct for passing parameters to the method [`list_repositories`]
55#[derive(Clone, Debug)]
56pub struct ListRepositoriesParams {
57    /// The name of the project
58    pub project_name: String,
59    /// An unique ID for the request
60    pub x_request_id: Option<String>,
61    /// 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]
62    pub q: Option<String>,
63    /// 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\"
64    pub sort: Option<String>,
65    /// The page number
66    pub page: Option<i64>,
67    /// The size of per page
68    pub page_size: Option<i64>
69}
70
71/// struct for passing parameters to the method [`update_repository`]
72#[derive(Clone, Debug)]
73pub struct UpdateRepositoryParams {
74    /// The name of the project
75    pub project_name: String,
76    /// The name of the repository. If it contains slash, encode it twice over with URL encoding. e.g. a/b -> a%2Fb -> a%252Fb
77    pub repository_name: String,
78    /// The JSON object of repository.
79    pub repository: models::Repository,
80    /// An unique ID for the request
81    pub x_request_id: Option<String>
82}
83
84
85/// struct for typed errors of method [`delete_repository`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum DeleteRepositoryError {
89    Status400(models::Errors),
90    Status401(models::Errors),
91    Status403(models::Errors),
92    Status404(models::Errors),
93    Status500(models::Errors),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`get_repository`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum GetRepositoryError {
101    Status400(models::Errors),
102    Status401(models::Errors),
103    Status403(models::Errors),
104    Status404(models::Errors),
105    Status500(models::Errors),
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`list_all_repositories`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum ListAllRepositoriesError {
113    Status400(models::Errors),
114    Status500(models::Errors),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`list_repositories`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum ListRepositoriesError {
122    Status400(models::Errors),
123    Status401(models::Errors),
124    Status403(models::Errors),
125    Status404(models::Errors),
126    Status500(models::Errors),
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`update_repository`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum UpdateRepositoryError {
134    Status400(models::Errors),
135    Status401(models::Errors),
136    Status403(models::Errors),
137    Status404(models::Errors),
138    Status500(models::Errors),
139    UnknownValue(serde_json::Value),
140}
141
142
143/// Delete the repository specified by name
144pub async fn delete_repository(configuration: &configuration::Configuration, params: DeleteRepositoryParams) -> Result<(), Error<DeleteRepositoryError>> {
145
146    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
147    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
148
149    if let Some(ref user_agent) = configuration.user_agent {
150        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
151    }
152    if let Some(param_value) = params.x_request_id {
153        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
154    }
155    if let Some(ref auth_conf) = configuration.basic_auth {
156        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
157    };
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163
164    if !status.is_client_error() && !status.is_server_error() {
165        Ok(())
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<DeleteRepositoryError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// Get the repository specified by name
174pub async fn get_repository(configuration: &configuration::Configuration, params: GetRepositoryParams) -> Result<models::Repository, Error<GetRepositoryError>> {
175
176    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
177    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
178
179    if let Some(ref user_agent) = configuration.user_agent {
180        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181    }
182    if let Some(param_value) = params.x_request_id {
183        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
184    }
185    if let Some(ref auth_conf) = configuration.basic_auth {
186        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
187    };
188
189    let req = req_builder.build()?;
190    let resp = configuration.client.execute(req).await?;
191
192    let status = resp.status();
193    let content_type = resp
194        .headers()
195        .get("content-type")
196        .and_then(|v| v.to_str().ok())
197        .unwrap_or("application/octet-stream");
198    let content_type = super::ContentType::from(content_type);
199
200    if !status.is_client_error() && !status.is_server_error() {
201        let content = resp.text().await?;
202        match content_type {
203            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Repository`"))),
205            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::Repository`")))),
206        }
207    } else {
208        let content = resp.text().await?;
209        let entity: Option<GetRepositoryError> = serde_json::from_str(&content).ok();
210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
211    }
212}
213
214/// List all authorized repositories
215pub async fn list_all_repositories(configuration: &configuration::Configuration, params: ListAllRepositoriesParams) -> Result<Vec<models::Repository>, Error<ListAllRepositoriesError>> {
216
217    let uri_str = format!("{}/repositories", configuration.base_path);
218    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220    if let Some(ref param_value) = params.q {
221        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
222    }
223    if let Some(ref param_value) = params.sort {
224        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
225    }
226    if let Some(ref param_value) = params.page {
227        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
228    }
229    if let Some(ref param_value) = params.page_size {
230        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
231    }
232    if let Some(ref user_agent) = configuration.user_agent {
233        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
234    }
235    if let Some(param_value) = params.x_request_id {
236        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
237    }
238    if let Some(ref auth_conf) = configuration.basic_auth {
239        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
240    };
241
242    let req = req_builder.build()?;
243    let resp = configuration.client.execute(req).await?;
244
245    let status = resp.status();
246    let content_type = resp
247        .headers()
248        .get("content-type")
249        .and_then(|v| v.to_str().ok())
250        .unwrap_or("application/octet-stream");
251    let content_type = super::ContentType::from(content_type);
252
253    if !status.is_client_error() && !status.is_server_error() {
254        let content = resp.text().await?;
255        match content_type {
256            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
257            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Repository&gt;`"))),
258            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::Repository&gt;`")))),
259        }
260    } else {
261        let content = resp.text().await?;
262        let entity: Option<ListAllRepositoriesError> = serde_json::from_str(&content).ok();
263        Err(Error::ResponseError(ResponseContent { status, content, entity }))
264    }
265}
266
267/// List repositories of the specified project
268pub async fn list_repositories(configuration: &configuration::Configuration, params: ListRepositoriesParams) -> Result<Vec<models::Repository>, Error<ListRepositoriesError>> {
269
270    let uri_str = format!("{}/projects/{project_name}/repositories", configuration.base_path, project_name=crate::apis::urlencode(params.project_name));
271    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273    if let Some(ref param_value) = params.q {
274        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
275    }
276    if let Some(ref param_value) = params.sort {
277        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
278    }
279    if let Some(ref param_value) = params.page {
280        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
281    }
282    if let Some(ref param_value) = params.page_size {
283        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
284    }
285    if let Some(ref user_agent) = configuration.user_agent {
286        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
287    }
288    if let Some(param_value) = params.x_request_id {
289        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
290    }
291    if let Some(ref auth_conf) = configuration.basic_auth {
292        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
293    };
294
295    let req = req_builder.build()?;
296    let resp = configuration.client.execute(req).await?;
297
298    let status = resp.status();
299    let content_type = resp
300        .headers()
301        .get("content-type")
302        .and_then(|v| v.to_str().ok())
303        .unwrap_or("application/octet-stream");
304    let content_type = super::ContentType::from(content_type);
305
306    if !status.is_client_error() && !status.is_server_error() {
307        let content = resp.text().await?;
308        match content_type {
309            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
310            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Repository&gt;`"))),
311            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::Repository&gt;`")))),
312        }
313    } else {
314        let content = resp.text().await?;
315        let entity: Option<ListRepositoriesError> = serde_json::from_str(&content).ok();
316        Err(Error::ResponseError(ResponseContent { status, content, entity }))
317    }
318}
319
320/// Update the repository specified by name
321pub async fn update_repository(configuration: &configuration::Configuration, params: UpdateRepositoryParams) -> Result<(), Error<UpdateRepositoryError>> {
322
323    let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
324    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
325
326    if let Some(ref user_agent) = configuration.user_agent {
327        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
328    }
329    if let Some(param_value) = params.x_request_id {
330        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
331    }
332    if let Some(ref auth_conf) = configuration.basic_auth {
333        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
334    };
335    req_builder = req_builder.json(&params.repository);
336
337    let req = req_builder.build()?;
338    let resp = configuration.client.execute(req).await?;
339
340    let status = resp.status();
341
342    if !status.is_client_error() && !status.is_server_error() {
343        Ok(())
344    } else {
345        let content = resp.text().await?;
346        let entity: Option<UpdateRepositoryError> = serde_json::from_str(&content).ok();
347        Err(Error::ResponseError(ResponseContent { status, content, entity }))
348    }
349}
350