Skip to main content

dtz_containerregistry/apis/
default_api.rs

1/*
2 * DTZ Container Registry
3 *
4 * a generated client for the DTZ Container Registry API
5 *
6 * Contact: jens@apimeister.com
7 * Generated by: https://openapi-generator.tech
8 */
9
10
11use reqwest;
12#[allow(unused_imports)]
13use serde::{de::Error as _};
14use crate::{apis::ResponseContent, models};
15#[allow(unused_imports)]
16use super::{Error, ContentType};
17use dtz_config::Configuration;
18
19fn build_url(config: &Configuration) -> String {
20    if let Some(base_path) = &config.base_path {
21        let base = url::Url::parse(base_path).unwrap();
22        let mut target_url = url::Url::parse(crate::apis::SVC_URL).unwrap();
23        let _ = target_url.set_scheme(base.scheme());
24        let _ = target_url.set_port(base.port());
25        let _ = target_url.set_host(Some(base.host_str().unwrap()));
26        format!("{target_url}")
27    } else {
28        crate::apis::SVC_URL.to_string()
29    }
30}
31
32
33/// struct for typed errors of method [`check_authentication`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum CheckAuthenticationError {
37    Status401(),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`disable_service`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum DisableServiceError {
45    Status401(models::ErrorMessage),
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`enable_service`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum EnableServiceError {
53    Status401(models::ErrorMessage),
54    Status500(models::ErrorMessage),
55    Status503(models::ErrorMessage),
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`get_catalog`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetCatalogError {
63    Status401(),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`get_image_tag_manifest`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum GetImageTagManifestError {
71    Status401(),
72    Status404(),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`get_image_tags_list`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetImageTagsListError {
80    Status401(),
81    Status500(),
82    UnknownValue(serde_json::Value),
83}
84
85/// struct for typed errors of method [`get_stats`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum GetStatsError {
89    Status401(),
90    UnknownValue(serde_json::Value),
91}
92
93
94/// check authentication
95pub async fn check_authentication(configuration: &Configuration) -> Result<(), Error<CheckAuthenticationError>> {
96
97    let uri_str = format!("{}/v2/", build_url(configuration));
98    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
99
100
101    if let Some(ref token) = configuration.oauth_access_token {
102        req_builder = req_builder.bearer_auth(token.to_owned());
103    };
104    if let Some(ref value) = configuration.api_key {
105        req_builder = req_builder.header("X-API-KEY", value);
106    };
107
108    let req = req_builder.build()?;
109    let resp = configuration.client.execute(req).await?;
110
111    let status = resp.status();
112
113    if !status.is_client_error() && !status.is_server_error() {
114        Ok(())
115    } else {
116        let content = resp.text().await?;
117        let entity: Option<CheckAuthenticationError> = serde_json::from_str(&content).ok();
118        Err(Error::ResponseError(ResponseContent { status, content, entity }))
119    }
120}
121
122/// disable the container registry service
123pub async fn disable_service(configuration: &Configuration) -> Result<(), Error<DisableServiceError>> {
124
125    let uri_str = format!("{}/disable", build_url(configuration));
126    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
127
128
129    if let Some(ref token) = configuration.oauth_access_token {
130        req_builder = req_builder.bearer_auth(token.to_owned());
131    };
132    if let Some(ref value) = configuration.api_key {
133        req_builder = req_builder.header("X-API-KEY", value);
134    };
135
136    let req = req_builder.build()?;
137    let resp = configuration.client.execute(req).await?;
138
139    let status = resp.status();
140
141    if !status.is_client_error() && !status.is_server_error() {
142        Ok(())
143    } else {
144        let content = resp.text().await?;
145        let entity: Option<DisableServiceError> = serde_json::from_str(&content).ok();
146        Err(Error::ResponseError(ResponseContent { status, content, entity }))
147    }
148}
149
150/// enable the container registry service
151pub async fn enable_service(configuration: &Configuration) -> Result<(), Error<EnableServiceError>> {
152
153    let uri_str = format!("{}/enable", build_url(configuration));
154    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
155
156
157    if let Some(ref token) = configuration.oauth_access_token {
158        req_builder = req_builder.bearer_auth(token.to_owned());
159    };
160    if let Some(ref value) = configuration.api_key {
161        req_builder = req_builder.header("X-API-KEY", value);
162    };
163
164    let req = req_builder.build()?;
165    let resp = configuration.client.execute(req).await?;
166
167    let status = resp.status();
168
169    if !status.is_client_error() && !status.is_server_error() {
170        Ok(())
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<EnableServiceError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178/// get catalog
179pub async fn get_catalog(configuration: &Configuration) -> Result<models::CatalogResponse, Error<GetCatalogError>> {
180
181    let uri_str = format!("{}/v2/_catalog", build_url(configuration));
182    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184
185    if let Some(ref token) = configuration.oauth_access_token {
186        req_builder = req_builder.bearer_auth(token.to_owned());
187    };
188    if let Some(ref value) = configuration.api_key {
189        req_builder = req_builder.header("X-API-KEY", value);
190    };
191
192    let req = req_builder.build()?;
193    let resp = configuration.client.execute(req).await?;
194
195    let status = resp.status();
196    let content_type = resp
197        .headers()
198        .get("content-type")
199        .and_then(|v| v.to_str().ok())
200        .unwrap_or("application/octet-stream");
201    let content_type = super::ContentType::from(content_type);
202
203    if !status.is_client_error() && !status.is_server_error() {
204        let content = resp.text().await?;
205        match content_type {
206            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CatalogResponse`"))),
208            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::CatalogResponse`")))),
209        }
210    } else {
211        let content = resp.text().await?;
212        let entity: Option<GetCatalogError> = serde_json::from_str(&content).ok();
213        Err(Error::ResponseError(ResponseContent { status, content, entity }))
214    }
215}
216
217/// get manifest for image and tag
218pub async fn get_image_tag_manifest(configuration: &Configuration, image: &str, tag: &str) -> Result<models::ManifestResponse, Error<GetImageTagManifestError>> {
219    // add a prefix to parameters to efficiently prevent name collisions
220    let p_path_image = image;
221    let p_path_tag = tag;
222
223    let uri_str = format!("{}/v2/{image}/manifests/{tag}", build_url(configuration), image=crate::apis::urlencode(p_path_image), tag=crate::apis::urlencode(p_path_tag));
224    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226
227    if let Some(ref token) = configuration.oauth_access_token {
228        req_builder = req_builder.bearer_auth(token.to_owned());
229    };
230    if let Some(ref value) = configuration.api_key {
231        req_builder = req_builder.header("X-API-KEY", value);
232    };
233
234    let req = req_builder.build()?;
235    let resp = configuration.client.execute(req).await?;
236
237    let status = resp.status();
238    let content_type = resp
239        .headers()
240        .get("content-type")
241        .and_then(|v| v.to_str().ok())
242        .unwrap_or("application/octet-stream");
243    let content_type = super::ContentType::from(content_type);
244
245    if !status.is_client_error() && !status.is_server_error() {
246        let content = resp.text().await?;
247        match content_type {
248            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ManifestResponse`"))),
250            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::ManifestResponse`")))),
251        }
252    } else {
253        let content = resp.text().await?;
254        let entity: Option<GetImageTagManifestError> = serde_json::from_str(&content).ok();
255        Err(Error::ResponseError(ResponseContent { status, content, entity }))
256    }
257}
258
259/// get tags list
260pub async fn get_image_tags_list(configuration: &Configuration, image: &str) -> Result<models::TagsListResponse, Error<GetImageTagsListError>> {
261    // add a prefix to parameters to efficiently prevent name collisions
262    let p_path_image = image;
263
264    let uri_str = format!("{}/v2/{image}/tags/list", build_url(configuration), image=crate::apis::urlencode(p_path_image));
265    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
266
267
268    if let Some(ref token) = configuration.oauth_access_token {
269        req_builder = req_builder.bearer_auth(token.to_owned());
270    };
271    if let Some(ref value) = configuration.api_key {
272        req_builder = req_builder.header("X-API-KEY", value);
273    };
274
275    let req = req_builder.build()?;
276    let resp = configuration.client.execute(req).await?;
277
278    let status = resp.status();
279    let content_type = resp
280        .headers()
281        .get("content-type")
282        .and_then(|v| v.to_str().ok())
283        .unwrap_or("application/octet-stream");
284    let content_type = super::ContentType::from(content_type);
285
286    if !status.is_client_error() && !status.is_server_error() {
287        let content = resp.text().await?;
288        match content_type {
289            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TagsListResponse`"))),
291            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::TagsListResponse`")))),
292        }
293    } else {
294        let content = resp.text().await?;
295        let entity: Option<GetImageTagsListError> = serde_json::from_str(&content).ok();
296        Err(Error::ResponseError(ResponseContent { status, content, entity }))
297    }
298}
299
300/// get stats
301pub async fn get_stats(configuration: &Configuration) -> Result<models::StatsResponse, Error<GetStatsError>> {
302
303    let uri_str = format!("{}/stats", build_url(configuration));
304    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
305
306
307    if let Some(ref token) = configuration.oauth_access_token {
308        req_builder = req_builder.bearer_auth(token.to_owned());
309    };
310    if let Some(ref value) = configuration.api_key {
311        req_builder = req_builder.header("X-API-KEY", value);
312    };
313
314    let req = req_builder.build()?;
315    let resp = configuration.client.execute(req).await?;
316
317    let status = resp.status();
318    let content_type = resp
319        .headers()
320        .get("content-type")
321        .and_then(|v| v.to_str().ok())
322        .unwrap_or("application/octet-stream");
323    let content_type = super::ContentType::from(content_type);
324
325    if !status.is_client_error() && !status.is_server_error() {
326        let content = resp.text().await?;
327        match content_type {
328            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StatsResponse`"))),
330            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::StatsResponse`")))),
331        }
332    } else {
333        let content = resp.text().await?;
334        let entity: Option<GetStatsError> = serde_json::from_str(&content).ok();
335        Err(Error::ResponseError(ResponseContent { status, content, entity }))
336    }
337}
338