1use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13
14use super::{ContentType, Error, configuration};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum CreateRegistryError {
21 Status400(models::GetFinances400Response),
22 Status401(models::GetFinances401Response),
23 Status429(models::GetFinances429Response),
24 Status500(models::GetFinances500Response),
25 UnknownValue(serde_json::Value)
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteRegistryError {
32 Status400(models::GetFinances400Response),
33 Status401(models::GetFinances401Response),
34 Status403(models::GetAccountStatus403Response),
35 Status404(models::GetImage404Response),
36 Status429(models::GetFinances429Response),
37 Status500(models::GetFinances500Response),
38 UnknownValue(serde_json::Value)
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetRegistriesError {
45 Status400(models::GetFinances400Response),
46 Status401(models::GetFinances401Response),
47 Status429(models::GetFinances429Response),
48 Status500(models::GetFinances500Response),
49 UnknownValue(serde_json::Value)
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetRegistryError {
56 Status400(models::GetFinances400Response),
57 Status401(models::GetFinances401Response),
58 Status403(models::GetAccountStatus403Response),
59 Status404(models::GetImage404Response),
60 Status429(models::GetFinances429Response),
61 Status500(models::GetFinances500Response),
62 UnknownValue(serde_json::Value)
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetRegistryPresetsError {
69 Status400(models::GetFinances400Response),
70 Status401(models::GetFinances401Response),
71 Status429(models::GetFinances429Response),
72 Status500(models::GetFinances500Response),
73 UnknownValue(serde_json::Value)
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetRegistryRepositoriesError {
80 Status400(models::GetFinances400Response),
81 Status401(models::GetFinances401Response),
82 Status429(models::GetFinances429Response),
83 Status500(models::GetFinances500Response),
84 UnknownValue(serde_json::Value)
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UpdateRegistryError {
91 Status400(models::GetFinances400Response),
92 Status401(models::GetFinances401Response),
93 Status403(models::GetAccountStatus403Response),
94 Status404(models::GetImage404Response),
95 Status429(models::GetFinances429Response),
96 Status500(models::GetFinances500Response),
97 UnknownValue(serde_json::Value)
98}
99
100pub async fn create_registry(
102 configuration: &configuration::Configuration,
103 registry_in: models::RegistryIn
104) -> Result<models::CreateRegistry201Response, Error<CreateRegistryError>> {
105 let p_body_registry_in = registry_in;
107
108 let uri_str = format!("{}/api/v1/container-registry", configuration.base_path);
109 let mut req_builder = configuration
110 .client
111 .request(reqwest::Method::POST, &uri_str);
112
113 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116 if let Some(ref token) = configuration.bearer_access_token {
117 req_builder = req_builder.bearer_auth(token.to_owned());
118 };
119 req_builder = req_builder.json(&p_body_registry_in);
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => {
137 return Err(Error::from(serde_json::Error::custom(
138 "Received `text/plain` content type response that cannot be converted to `models::CreateRegistry201Response`"
139 )));
140 }
141 ContentType::Unsupported(unknown_type) => {
142 return Err(Error::from(serde_json::Error::custom(format!(
143 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateRegistry201Response`"
144 ))));
145 }
146 }
147 } else {
148 let content = resp.text().await?;
149 let entity: Option<CreateRegistryError> = serde_json::from_str(&content).ok();
150 Err(Error::ResponseError(ResponseContent {
151 status,
152 content,
153 entity
154 }))
155 }
156}
157
158pub async fn delete_registry(
161 configuration: &configuration::Configuration,
162 registry_id: i32
163) -> Result<(), Error<DeleteRegistryError>> {
164 let p_path_registry_id = registry_id;
166
167 let uri_str = format!(
168 "{}/api/v1/container-registry/{registry_id}",
169 configuration.base_path,
170 registry_id = p_path_registry_id
171 );
172 let mut req_builder = configuration
173 .client
174 .request(reqwest::Method::DELETE, &uri_str);
175
176 if let Some(ref user_agent) = configuration.user_agent {
177 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
178 }
179 if let Some(ref token) = configuration.bearer_access_token {
180 req_builder = req_builder.bearer_auth(token.to_owned());
181 };
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187
188 if !status.is_client_error() && !status.is_server_error() {
189 Ok(())
190 } else {
191 let content = resp.text().await?;
192 let entity: Option<DeleteRegistryError> = serde_json::from_str(&content).ok();
193 Err(Error::ResponseError(ResponseContent {
194 status,
195 content,
196 entity
197 }))
198 }
199}
200
201pub async fn get_registries(
204 configuration: &configuration::Configuration
205) -> Result<models::GetRegistries200Response, Error<GetRegistriesError>> {
206 let uri_str = format!("{}/api/v1/container-registry", configuration.base_path);
207 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
208
209 if let Some(ref user_agent) = configuration.user_agent {
210 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
211 }
212 if let Some(ref token) = configuration.bearer_access_token {
213 req_builder = req_builder.bearer_auth(token.to_owned());
214 };
215
216 let req = req_builder.build()?;
217 let resp = configuration.client.execute(req).await?;
218
219 let status = resp.status();
220 let content_type = resp
221 .headers()
222 .get("content-type")
223 .and_then(|v| v.to_str().ok())
224 .unwrap_or("application/octet-stream");
225 let content_type = super::ContentType::from(content_type);
226
227 if !status.is_client_error() && !status.is_server_error() {
228 let content = resp.text().await?;
229 match content_type {
230 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
231 ContentType::Text => {
232 return Err(Error::from(serde_json::Error::custom(
233 "Received `text/plain` content type response that cannot be converted to `models::GetRegistries200Response`"
234 )));
235 }
236 ContentType::Unsupported(unknown_type) => {
237 return Err(Error::from(serde_json::Error::custom(format!(
238 "Received `{unknown_type}` content type response that cannot be converted to `models::GetRegistries200Response`"
239 ))));
240 }
241 }
242 } else {
243 let content = resp.text().await?;
244 let entity: Option<GetRegistriesError> = serde_json::from_str(&content).ok();
245 Err(Error::ResponseError(ResponseContent {
246 status,
247 content,
248 entity
249 }))
250 }
251}
252
253pub async fn get_registry(
256 configuration: &configuration::Configuration,
257 registry_id: i32
258) -> Result<models::CreateRegistry201Response, Error<GetRegistryError>> {
259 let p_path_registry_id = registry_id;
261
262 let uri_str = format!(
263 "{}/api/v1/container-registry/{registry_id}",
264 configuration.base_path,
265 registry_id = p_path_registry_id
266 );
267 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
268
269 if let Some(ref user_agent) = configuration.user_agent {
270 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271 }
272 if let Some(ref token) = configuration.bearer_access_token {
273 req_builder = req_builder.bearer_auth(token.to_owned());
274 };
275
276 let req = req_builder.build()?;
277 let resp = configuration.client.execute(req).await?;
278
279 let status = resp.status();
280 let content_type = resp
281 .headers()
282 .get("content-type")
283 .and_then(|v| v.to_str().ok())
284 .unwrap_or("application/octet-stream");
285 let content_type = super::ContentType::from(content_type);
286
287 if !status.is_client_error() && !status.is_server_error() {
288 let content = resp.text().await?;
289 match content_type {
290 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
291 ContentType::Text => {
292 return Err(Error::from(serde_json::Error::custom(
293 "Received `text/plain` content type response that cannot be converted to `models::CreateRegistry201Response`"
294 )));
295 }
296 ContentType::Unsupported(unknown_type) => {
297 return Err(Error::from(serde_json::Error::custom(format!(
298 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateRegistry201Response`"
299 ))));
300 }
301 }
302 } else {
303 let content = resp.text().await?;
304 let entity: Option<GetRegistryError> = serde_json::from_str(&content).ok();
305 Err(Error::ResponseError(ResponseContent {
306 status,
307 content,
308 entity
309 }))
310 }
311}
312
313pub async fn get_registry_presets(
316 configuration: &configuration::Configuration
317) -> Result<models::GetRegistryPresets200Response, Error<GetRegistryPresetsError>> {
318 let uri_str = format!(
319 "{}/api/v1/container-registry/presets",
320 configuration.base_path
321 );
322 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
323
324 if let Some(ref user_agent) = configuration.user_agent {
325 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
326 }
327 if let Some(ref token) = configuration.bearer_access_token {
328 req_builder = req_builder.bearer_auth(token.to_owned());
329 };
330
331 let req = req_builder.build()?;
332 let resp = configuration.client.execute(req).await?;
333
334 let status = resp.status();
335 let content_type = resp
336 .headers()
337 .get("content-type")
338 .and_then(|v| v.to_str().ok())
339 .unwrap_or("application/octet-stream");
340 let content_type = super::ContentType::from(content_type);
341
342 if !status.is_client_error() && !status.is_server_error() {
343 let content = resp.text().await?;
344 match content_type {
345 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
346 ContentType::Text => {
347 return Err(Error::from(serde_json::Error::custom(
348 "Received `text/plain` content type response that cannot be converted to `models::GetRegistryPresets200Response`"
349 )));
350 }
351 ContentType::Unsupported(unknown_type) => {
352 return Err(Error::from(serde_json::Error::custom(format!(
353 "Received `{unknown_type}` content type response that cannot be converted to `models::GetRegistryPresets200Response`"
354 ))));
355 }
356 }
357 } else {
358 let content = resp.text().await?;
359 let entity: Option<GetRegistryPresetsError> = serde_json::from_str(&content).ok();
360 Err(Error::ResponseError(ResponseContent {
361 status,
362 content,
363 entity
364 }))
365 }
366}
367
368pub async fn get_registry_repositories(
371 configuration: &configuration::Configuration,
372 registry_id: i32
373) -> Result<models::GetRegistryRepositories200Response, Error<GetRegistryRepositoriesError>> {
374 let p_path_registry_id = registry_id;
376
377 let uri_str = format!(
378 "{}/api/v1/container-registry/{registry_id}/repositories",
379 configuration.base_path,
380 registry_id = p_path_registry_id
381 );
382 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
383
384 if let Some(ref user_agent) = configuration.user_agent {
385 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
386 }
387 if let Some(ref token) = configuration.bearer_access_token {
388 req_builder = req_builder.bearer_auth(token.to_owned());
389 };
390
391 let req = req_builder.build()?;
392 let resp = configuration.client.execute(req).await?;
393
394 let status = resp.status();
395 let content_type = resp
396 .headers()
397 .get("content-type")
398 .and_then(|v| v.to_str().ok())
399 .unwrap_or("application/octet-stream");
400 let content_type = super::ContentType::from(content_type);
401
402 if !status.is_client_error() && !status.is_server_error() {
403 let content = resp.text().await?;
404 match content_type {
405 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
406 ContentType::Text => {
407 return Err(Error::from(serde_json::Error::custom(
408 "Received `text/plain` content type response that cannot be converted to `models::GetRegistryRepositories200Response`"
409 )));
410 }
411 ContentType::Unsupported(unknown_type) => {
412 return Err(Error::from(serde_json::Error::custom(format!(
413 "Received `{unknown_type}` content type response that cannot be converted to `models::GetRegistryRepositories200Response`"
414 ))));
415 }
416 }
417 } else {
418 let content = resp.text().await?;
419 let entity: Option<GetRegistryRepositoriesError> = serde_json::from_str(&content).ok();
420 Err(Error::ResponseError(ResponseContent {
421 status,
422 content,
423 entity
424 }))
425 }
426}
427
428pub async fn update_registry(
431 configuration: &configuration::Configuration,
432 registry_id: i32,
433 registry_edit: models::RegistryEdit
434) -> Result<models::CreateRegistry201Response, Error<UpdateRegistryError>> {
435 let p_path_registry_id = registry_id;
437 let p_body_registry_edit = registry_edit;
438
439 let uri_str = format!(
440 "{}/api/v1/container-registry/{registry_id}",
441 configuration.base_path,
442 registry_id = p_path_registry_id
443 );
444 let mut req_builder = configuration
445 .client
446 .request(reqwest::Method::PATCH, &uri_str);
447
448 if let Some(ref user_agent) = configuration.user_agent {
449 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
450 }
451 if let Some(ref token) = configuration.bearer_access_token {
452 req_builder = req_builder.bearer_auth(token.to_owned());
453 };
454 req_builder = req_builder.json(&p_body_registry_edit);
455
456 let req = req_builder.build()?;
457 let resp = configuration.client.execute(req).await?;
458
459 let status = resp.status();
460 let content_type = resp
461 .headers()
462 .get("content-type")
463 .and_then(|v| v.to_str().ok())
464 .unwrap_or("application/octet-stream");
465 let content_type = super::ContentType::from(content_type);
466
467 if !status.is_client_error() && !status.is_server_error() {
468 let content = resp.text().await?;
469 match content_type {
470 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
471 ContentType::Text => {
472 return Err(Error::from(serde_json::Error::custom(
473 "Received `text/plain` content type response that cannot be converted to `models::CreateRegistry201Response`"
474 )));
475 }
476 ContentType::Unsupported(unknown_type) => {
477 return Err(Error::from(serde_json::Error::custom(format!(
478 "Received `{unknown_type}` content type response that cannot be converted to `models::CreateRegistry201Response`"
479 ))));
480 }
481 }
482 } else {
483 let content = resp.text().await?;
484 let entity: Option<UpdateRegistryError> = serde_json::from_str(&content).ok();
485 Err(Error::ResponseError(ResponseContent {
486 status,
487 content,
488 entity
489 }))
490 }
491}