harbor_api/apis/
registry_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 [`create_registry`]
18#[derive(Clone, Debug)]
19pub struct CreateRegistryParams {
20    /// The registry
21    pub registry: models::Registry,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`delete_registry`]
27#[derive(Clone, Debug)]
28pub struct DeleteRegistryParams {
29    /// Registry ID
30    pub id: i64,
31    /// An unique ID for the request
32    pub x_request_id: Option<String>
33}
34
35/// struct for passing parameters to the method [`get_registry`]
36#[derive(Clone, Debug)]
37pub struct GetRegistryParams {
38    /// Registry ID
39    pub id: i64,
40    /// An unique ID for the request
41    pub x_request_id: Option<String>
42}
43
44/// struct for passing parameters to the method [`get_registry_info`]
45#[derive(Clone, Debug)]
46pub struct GetRegistryInfoParams {
47    /// Registry ID
48    pub id: i64,
49    /// An unique ID for the request
50    pub x_request_id: Option<String>
51}
52
53/// struct for passing parameters to the method [`list_registries`]
54#[derive(Clone, Debug)]
55pub struct ListRegistriesParams {
56    /// An unique ID for the request
57    pub x_request_id: Option<String>,
58    /// 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]
59    pub q: Option<String>,
60    /// 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\"
61    pub sort: Option<String>,
62    /// The page number
63    pub page: Option<i64>,
64    /// The size of per page
65    pub page_size: Option<i64>,
66    /// Deprecated, use `q` instead.
67    pub name: Option<String>
68}
69
70/// struct for passing parameters to the method [`list_registry_provider_infos`]
71#[derive(Clone, Debug)]
72pub struct ListRegistryProviderInfosParams {
73    /// An unique ID for the request
74    pub x_request_id: Option<String>
75}
76
77/// struct for passing parameters to the method [`list_registry_provider_types`]
78#[derive(Clone, Debug)]
79pub struct ListRegistryProviderTypesParams {
80    /// An unique ID for the request
81    pub x_request_id: Option<String>
82}
83
84/// struct for passing parameters to the method [`ping_registry`]
85#[derive(Clone, Debug)]
86pub struct PingRegistryParams {
87    /// The registry
88    pub registry: models::RegistryPing,
89    /// An unique ID for the request
90    pub x_request_id: Option<String>
91}
92
93/// struct for passing parameters to the method [`update_registry`]
94#[derive(Clone, Debug)]
95pub struct UpdateRegistryParams {
96    /// The registry ID
97    pub id: i64,
98    /// The registry
99    pub registry: models::RegistryUpdate,
100    /// An unique ID for the request
101    pub x_request_id: Option<String>
102}
103
104
105/// struct for typed errors of method [`create_registry`]
106#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(untagged)]
108pub enum CreateRegistryError {
109    Status400(models::Errors),
110    Status401(models::Errors),
111    Status403(models::Errors),
112    Status409(models::Errors),
113    Status500(models::Errors),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`delete_registry`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum DeleteRegistryError {
121    Status401(models::Errors),
122    Status403(models::Errors),
123    Status404(models::Errors),
124    Status412(models::Errors),
125    Status500(models::Errors),
126    UnknownValue(serde_json::Value),
127}
128
129/// struct for typed errors of method [`get_registry`]
130#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(untagged)]
132pub enum GetRegistryError {
133    Status401(models::Errors),
134    Status403(models::Errors),
135    Status404(models::Errors),
136    Status500(models::Errors),
137    UnknownValue(serde_json::Value),
138}
139
140/// struct for typed errors of method [`get_registry_info`]
141#[derive(Debug, Clone, Serialize, Deserialize)]
142#[serde(untagged)]
143pub enum GetRegistryInfoError {
144    Status401(models::Errors),
145    Status403(models::Errors),
146    Status404(models::Errors),
147    Status500(models::Errors),
148    UnknownValue(serde_json::Value),
149}
150
151/// struct for typed errors of method [`list_registries`]
152#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum ListRegistriesError {
155    Status401(models::Errors),
156    Status403(models::Errors),
157    Status500(models::Errors),
158    UnknownValue(serde_json::Value),
159}
160
161/// struct for typed errors of method [`list_registry_provider_infos`]
162#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum ListRegistryProviderInfosError {
165    Status401(models::Errors),
166    Status403(models::Errors),
167    Status500(models::Errors),
168    UnknownValue(serde_json::Value),
169}
170
171/// struct for typed errors of method [`list_registry_provider_types`]
172#[derive(Debug, Clone, Serialize, Deserialize)]
173#[serde(untagged)]
174pub enum ListRegistryProviderTypesError {
175    Status401(models::Errors),
176    Status403(models::Errors),
177    Status500(models::Errors),
178    UnknownValue(serde_json::Value),
179}
180
181/// struct for typed errors of method [`ping_registry`]
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(untagged)]
184pub enum PingRegistryError {
185    Status400(models::Errors),
186    Status401(models::Errors),
187    Status403(models::Errors),
188    Status404(models::Errors),
189    Status500(models::Errors),
190    UnknownValue(serde_json::Value),
191}
192
193/// struct for typed errors of method [`update_registry`]
194#[derive(Debug, Clone, Serialize, Deserialize)]
195#[serde(untagged)]
196pub enum UpdateRegistryError {
197    Status401(models::Errors),
198    Status403(models::Errors),
199    Status404(models::Errors),
200    Status409(models::Errors),
201    Status500(models::Errors),
202    UnknownValue(serde_json::Value),
203}
204
205
206/// Create a registry
207pub async fn create_registry(configuration: &configuration::Configuration, params: CreateRegistryParams) -> Result<(), Error<CreateRegistryError>> {
208
209    let uri_str = format!("{}/registries", configuration.base_path);
210    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
211
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(param_value) = params.x_request_id {
216        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
217    }
218    if let Some(ref auth_conf) = configuration.basic_auth {
219        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
220    };
221    req_builder = req_builder.json(&params.registry);
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227
228    if !status.is_client_error() && !status.is_server_error() {
229        Ok(())
230    } else {
231        let content = resp.text().await?;
232        let entity: Option<CreateRegistryError> = serde_json::from_str(&content).ok();
233        Err(Error::ResponseError(ResponseContent { status, content, entity }))
234    }
235}
236
237/// Delete the specific registry
238pub async fn delete_registry(configuration: &configuration::Configuration, params: DeleteRegistryParams) -> Result<(), Error<DeleteRegistryError>> {
239
240    let uri_str = format!("{}/registries/{id}", configuration.base_path, id=params.id);
241    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
242
243    if let Some(ref user_agent) = configuration.user_agent {
244        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
245    }
246    if let Some(param_value) = params.x_request_id {
247        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
248    }
249    if let Some(ref auth_conf) = configuration.basic_auth {
250        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
251    };
252
253    let req = req_builder.build()?;
254    let resp = configuration.client.execute(req).await?;
255
256    let status = resp.status();
257
258    if !status.is_client_error() && !status.is_server_error() {
259        Ok(())
260    } else {
261        let content = resp.text().await?;
262        let entity: Option<DeleteRegistryError> = serde_json::from_str(&content).ok();
263        Err(Error::ResponseError(ResponseContent { status, content, entity }))
264    }
265}
266
267/// Get the specific registry
268pub async fn get_registry(configuration: &configuration::Configuration, params: GetRegistryParams) -> Result<models::Registry, Error<GetRegistryError>> {
269
270    let uri_str = format!("{}/registries/{id}", configuration.base_path, id=params.id);
271    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273    if let Some(ref user_agent) = configuration.user_agent {
274        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275    }
276    if let Some(param_value) = params.x_request_id {
277        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
278    }
279    if let Some(ref auth_conf) = configuration.basic_auth {
280        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
281    };
282
283    let req = req_builder.build()?;
284    let resp = configuration.client.execute(req).await?;
285
286    let status = resp.status();
287    let content_type = resp
288        .headers()
289        .get("content-type")
290        .and_then(|v| v.to_str().ok())
291        .unwrap_or("application/octet-stream");
292    let content_type = super::ContentType::from(content_type);
293
294    if !status.is_client_error() && !status.is_server_error() {
295        let content = resp.text().await?;
296        match content_type {
297            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
298            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Registry`"))),
299            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::Registry`")))),
300        }
301    } else {
302        let content = resp.text().await?;
303        let entity: Option<GetRegistryError> = serde_json::from_str(&content).ok();
304        Err(Error::ResponseError(ResponseContent { status, content, entity }))
305    }
306}
307
308/// Get the registry info
309pub async fn get_registry_info(configuration: &configuration::Configuration, params: GetRegistryInfoParams) -> Result<models::RegistryInfo, Error<GetRegistryInfoError>> {
310
311    let uri_str = format!("{}/registries/{id}/info", configuration.base_path, id=params.id);
312    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
313
314    if let Some(ref user_agent) = configuration.user_agent {
315        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316    }
317    if let Some(param_value) = params.x_request_id {
318        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
319    }
320    if let Some(ref auth_conf) = configuration.basic_auth {
321        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
322    };
323
324    let req = req_builder.build()?;
325    let resp = configuration.client.execute(req).await?;
326
327    let status = resp.status();
328    let content_type = resp
329        .headers()
330        .get("content-type")
331        .and_then(|v| v.to_str().ok())
332        .unwrap_or("application/octet-stream");
333    let content_type = super::ContentType::from(content_type);
334
335    if !status.is_client_error() && !status.is_server_error() {
336        let content = resp.text().await?;
337        match content_type {
338            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
339            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryInfo`"))),
340            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::RegistryInfo`")))),
341        }
342    } else {
343        let content = resp.text().await?;
344        let entity: Option<GetRegistryInfoError> = serde_json::from_str(&content).ok();
345        Err(Error::ResponseError(ResponseContent { status, content, entity }))
346    }
347}
348
349/// List the registries
350pub async fn list_registries(configuration: &configuration::Configuration, params: ListRegistriesParams) -> Result<Vec<models::Registry>, Error<ListRegistriesError>> {
351
352    let uri_str = format!("{}/registries", configuration.base_path);
353    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
354
355    if let Some(ref param_value) = params.q {
356        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
357    }
358    if let Some(ref param_value) = params.sort {
359        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
360    }
361    if let Some(ref param_value) = params.page {
362        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
363    }
364    if let Some(ref param_value) = params.page_size {
365        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
366    }
367    if let Some(ref param_value) = params.name {
368        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
369    }
370    if let Some(ref user_agent) = configuration.user_agent {
371        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
372    }
373    if let Some(param_value) = params.x_request_id {
374        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
375    }
376    if let Some(ref auth_conf) = configuration.basic_auth {
377        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
378    };
379
380    let req = req_builder.build()?;
381    let resp = configuration.client.execute(req).await?;
382
383    let status = resp.status();
384    let content_type = resp
385        .headers()
386        .get("content-type")
387        .and_then(|v| v.to_str().ok())
388        .unwrap_or("application/octet-stream");
389    let content_type = super::ContentType::from(content_type);
390
391    if !status.is_client_error() && !status.is_server_error() {
392        let content = resp.text().await?;
393        match content_type {
394            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
395            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Registry&gt;`"))),
396            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::Registry&gt;`")))),
397        }
398    } else {
399        let content = resp.text().await?;
400        let entity: Option<ListRegistriesError> = serde_json::from_str(&content).ok();
401        Err(Error::ResponseError(ResponseContent { status, content, entity }))
402    }
403}
404
405/// List all registered registry provider information
406pub async fn list_registry_provider_infos(configuration: &configuration::Configuration, params: ListRegistryProviderInfosParams) -> Result<std::collections::HashMap<String, models::RegistryProviderInfo>, Error<ListRegistryProviderInfosError>> {
407
408    let uri_str = format!("{}/replication/adapterinfos", configuration.base_path);
409    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
410
411    if let Some(ref user_agent) = configuration.user_agent {
412        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
413    }
414    if let Some(param_value) = params.x_request_id {
415        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
416    }
417    if let Some(ref auth_conf) = configuration.basic_auth {
418        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
419    };
420
421    let req = req_builder.build()?;
422    let resp = configuration.client.execute(req).await?;
423
424    let status = resp.status();
425    let content_type = resp
426        .headers()
427        .get("content-type")
428        .and_then(|v| v.to_str().ok())
429        .unwrap_or("application/octet-stream");
430    let content_type = super::ContentType::from(content_type);
431
432    if !status.is_client_error() && !status.is_server_error() {
433        let content = resp.text().await?;
434        match content_type {
435            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
436            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::RegistryProviderInfo&gt;`"))),
437            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::RegistryProviderInfo&gt;`")))),
438        }
439    } else {
440        let content = resp.text().await?;
441        let entity: Option<ListRegistryProviderInfosError> = serde_json::from_str(&content).ok();
442        Err(Error::ResponseError(ResponseContent { status, content, entity }))
443    }
444}
445
446/// List registry adapters
447pub async fn list_registry_provider_types(configuration: &configuration::Configuration, params: ListRegistryProviderTypesParams) -> Result<Vec<String>, Error<ListRegistryProviderTypesError>> {
448
449    let uri_str = format!("{}/replication/adapters", configuration.base_path);
450    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
451
452    if let Some(ref user_agent) = configuration.user_agent {
453        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
454    }
455    if let Some(param_value) = params.x_request_id {
456        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
457    }
458    if let Some(ref auth_conf) = configuration.basic_auth {
459        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
460    };
461
462    let req = req_builder.build()?;
463    let resp = configuration.client.execute(req).await?;
464
465    let status = resp.status();
466    let content_type = resp
467        .headers()
468        .get("content-type")
469        .and_then(|v| v.to_str().ok())
470        .unwrap_or("application/octet-stream");
471    let content_type = super::ContentType::from(content_type);
472
473    if !status.is_client_error() && !status.is_server_error() {
474        let content = resp.text().await?;
475        match content_type {
476            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
477            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;String&gt;`"))),
478            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;String&gt;`")))),
479        }
480    } else {
481        let content = resp.text().await?;
482        let entity: Option<ListRegistryProviderTypesError> = serde_json::from_str(&content).ok();
483        Err(Error::ResponseError(ResponseContent { status, content, entity }))
484    }
485}
486
487/// Check status of a registry
488pub async fn ping_registry(configuration: &configuration::Configuration, params: PingRegistryParams) -> Result<(), Error<PingRegistryError>> {
489
490    let uri_str = format!("{}/registries/ping", configuration.base_path);
491    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
492
493    if let Some(ref user_agent) = configuration.user_agent {
494        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
495    }
496    if let Some(param_value) = params.x_request_id {
497        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
498    }
499    if let Some(ref auth_conf) = configuration.basic_auth {
500        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
501    };
502    req_builder = req_builder.json(&params.registry);
503
504    let req = req_builder.build()?;
505    let resp = configuration.client.execute(req).await?;
506
507    let status = resp.status();
508
509    if !status.is_client_error() && !status.is_server_error() {
510        Ok(())
511    } else {
512        let content = resp.text().await?;
513        let entity: Option<PingRegistryError> = serde_json::from_str(&content).ok();
514        Err(Error::ResponseError(ResponseContent { status, content, entity }))
515    }
516}
517
518/// Update the registry
519pub async fn update_registry(configuration: &configuration::Configuration, params: UpdateRegistryParams) -> Result<(), Error<UpdateRegistryError>> {
520
521    let uri_str = format!("{}/registries/{id}", configuration.base_path, id=params.id);
522    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
523
524    if let Some(ref user_agent) = configuration.user_agent {
525        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
526    }
527    if let Some(param_value) = params.x_request_id {
528        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
529    }
530    if let Some(ref auth_conf) = configuration.basic_auth {
531        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
532    };
533    req_builder = req_builder.json(&params.registry);
534
535    let req = req_builder.build()?;
536    let resp = configuration.client.execute(req).await?;
537
538    let status = resp.status();
539
540    if !status.is_client_error() && !status.is_server_error() {
541        Ok(())
542    } else {
543        let content = resp.text().await?;
544        let entity: Option<UpdateRegistryError> = serde_json::from_str(&content).ok();
545        Err(Error::ResponseError(ResponseContent { status, content, entity }))
546    }
547}
548