podman_rest_client/v4/apis/
images_compat.rs1use crate::api_common::config::HasConfig;
2use crate::api_common::request;
3use crate::api_common::Error;
4use http::request::Builder;
5use std::future::Future;
6use std::pin::Pin;
7pub trait ImagesCompat: HasConfig + Send + Sync {
8 fn image_build<'a>(
14 &'a self,
15 params: Option<crate::v4::params::ImageBuild<'a>>,
16 input_stream: String,
17 ) -> Pin<Box<dyn Future<Output = Result<crate::v4::models::ImageBuild200, Error>> + Send + 'a>>
18 {
19 Box::pin(request::execute_request_json(
20 self.get_config(),
21 move |mut req_builder: Builder| {
22 req_builder = req_builder.method("POST");
23 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
24 let mut request_path = request_url.path().to_owned();
25 if request_path.ends_with('/') {
26 request_path.pop();
27 }
28 request_path.push_str("/build");
29 request_url.set_path(&request_path);
30 if let Some(params) = ¶ms {
31 let mut query_pairs = request_url.query_pairs_mut();
32 if let Some(dockerfile) = params.dockerfile {
33 query_pairs.append_pair("dockerfile", dockerfile);
34 }
35 if let Some(t) = params.t {
36 query_pairs.append_pair("t", t);
37 }
38 if let Some(extrahosts) = params.extrahosts {
39 query_pairs.append_pair("extrahosts", extrahosts);
40 }
41 if let Some(remote) = params.remote {
42 query_pairs.append_pair("remote", remote);
43 }
44 if let Some(q) = params.q {
45 query_pairs.append_pair("q", &q.to_string());
46 }
47 if let Some(nocache) = params.nocache {
48 query_pairs.append_pair("nocache", &nocache.to_string());
49 }
50 if let Some(cachefrom) = params.cachefrom {
51 query_pairs.append_pair("cachefrom", cachefrom);
52 }
53 if let Some(pull) = params.pull {
54 query_pairs.append_pair("pull", &pull.to_string());
55 }
56 if let Some(rm) = params.rm {
57 query_pairs.append_pair("rm", &rm.to_string());
58 }
59 if let Some(forcerm) = params.forcerm {
60 query_pairs.append_pair("forcerm", &forcerm.to_string());
61 }
62 if let Some(memory) = params.memory {
63 query_pairs.append_pair("memory", &memory.to_string());
64 }
65 if let Some(memswap) = params.memswap {
66 query_pairs.append_pair("memswap", &memswap.to_string());
67 }
68 if let Some(cpushares) = params.cpushares {
69 query_pairs.append_pair("cpushares", &cpushares.to_string());
70 }
71 if let Some(cpusetcpus) = params.cpusetcpus {
72 query_pairs.append_pair("cpusetcpus", cpusetcpus);
73 }
74 if let Some(cpuperiod) = params.cpuperiod {
75 query_pairs.append_pair("cpuperiod", &cpuperiod.to_string());
76 }
77 if let Some(cpuquota) = params.cpuquota {
78 query_pairs.append_pair("cpuquota", &cpuquota.to_string());
79 }
80 if let Some(buildargs) = params.buildargs {
81 query_pairs.append_pair("buildargs", buildargs);
82 }
83 if let Some(shmsize) = params.shmsize {
84 query_pairs.append_pair("shmsize", &shmsize.to_string());
85 }
86 if let Some(squash) = params.squash {
87 query_pairs.append_pair("squash", &squash.to_string());
88 }
89 if let Some(labels) = params.labels {
90 query_pairs.append_pair("labels", labels);
91 }
92 if let Some(networkmode) = params.networkmode {
93 query_pairs.append_pair("networkmode", networkmode);
94 }
95 if let Some(platform) = params.platform {
96 query_pairs.append_pair("platform", platform);
97 }
98 if let Some(target) = params.target {
99 query_pairs.append_pair("target", target);
100 }
101 if let Some(outputs) = params.outputs {
102 query_pairs.append_pair("outputs", outputs);
103 }
104 if let Some(content_type) = params.content_type {
105 req_builder = req_builder.header("Content-Type", content_type);
106 }
107 if let Some(x_registry_config) = params.x_registry_config {
108 req_builder = req_builder.header("X-Registry-Config", x_registry_config);
109 }
110 }
111 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
112 req_builder = req_builder.uri(hyper_uri);
113 let body = serde_json::to_string(&input_stream)?;
114 req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
115 req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
116 Ok(req_builder.body(body)?)
117 },
118 ))
119 }
120 fn image_delete<'a>(
126 &'a self,
127 name: &'a str,
128 params: Option<crate::v4::params::ImageDelete>,
129 ) -> Pin<Box<dyn Future<Output = Result<Vec<()>, Error>> + Send + 'a>> {
130 Box::pin(request::execute_request_json(
131 self.get_config(),
132 move |mut req_builder: Builder| {
133 req_builder = req_builder.method("DELETE");
134 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
135 let mut request_path = request_url.path().to_owned();
136 if request_path.ends_with('/') {
137 request_path.pop();
138 }
139 request_path.push_str("/images/{name}");
140 request_path = request_path.replace("{name}", name);
141 request_url.set_path(&request_path);
142 if let Some(params) = ¶ms {
143 let mut query_pairs = request_url.query_pairs_mut();
144 if let Some(force) = params.force {
145 query_pairs.append_pair("force", &force.to_string());
146 }
147 if let Some(noprune) = params.noprune {
148 query_pairs.append_pair("noprune", &noprune.to_string());
149 }
150 }
151 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
152 req_builder = req_builder.uri(hyper_uri);
153 Ok(req_builder.body(String::new())?)
154 },
155 ))
156 }
157 fn image_get<'a>(
163 &'a self,
164 name: &'a str,
165 ) -> Pin<Box<dyn futures::stream::Stream<Item = Result<bytes::Bytes, Error>> + Send + 'a>> {
166 request::execute_request_stream(self.get_config(), move |mut req_builder: Builder| {
167 req_builder = req_builder.method("GET");
168 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
169 let mut request_path = request_url.path().to_owned();
170 if request_path.ends_with('/') {
171 request_path.pop();
172 }
173 request_path.push_str("/images/{name}/get");
174 request_path = request_path.replace("{name}", name);
175 request_url.set_path(&request_path);
176 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
177 req_builder = req_builder.uri(hyper_uri);
178 Ok(req_builder.body(String::new())?)
179 })
180 }
181 fn image_history<'a>(
187 &'a self,
188 name: &'a str,
189 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
190 Box::pin(request::execute_request_unit(
191 self.get_config(),
192 move |mut req_builder: Builder| {
193 req_builder = req_builder.method("GET");
194 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
195 let mut request_path = request_url.path().to_owned();
196 if request_path.ends_with('/') {
197 request_path.pop();
198 }
199 request_path.push_str("/images/{name}/history");
200 request_path = request_path.replace("{name}", name);
201 request_url.set_path(&request_path);
202 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
203 req_builder = req_builder.uri(hyper_uri);
204 Ok(req_builder.body(String::new())?)
205 },
206 ))
207 }
208 fn image_inspect<'a>(
214 &'a self,
215 name: &'a str,
216 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
217 Box::pin(request::execute_request_unit(
218 self.get_config(),
219 move |mut req_builder: Builder| {
220 req_builder = req_builder.method("GET");
221 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
222 let mut request_path = request_url.path().to_owned();
223 if request_path.ends_with('/') {
224 request_path.pop();
225 }
226 request_path.push_str("/images/{name}/json");
227 request_path = request_path.replace("{name}", name);
228 request_url.set_path(&request_path);
229 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
230 req_builder = req_builder.uri(hyper_uri);
231 Ok(req_builder.body(String::new())?)
232 },
233 ))
234 }
235 fn image_push<'a>(
241 &'a self,
242 name: &'a str,
243 params: Option<crate::v4::params::ImagePush<'a>>,
244 ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'a>> {
245 Box::pin(request::execute_request_json(
246 self.get_config(),
247 move |mut req_builder: Builder| {
248 req_builder = req_builder.method("POST");
249 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
250 let mut request_path = request_url.path().to_owned();
251 if request_path.ends_with('/') {
252 request_path.pop();
253 }
254 request_path.push_str("/images/{name}/push");
255 request_path = request_path.replace("{name}", name);
256 request_url.set_path(&request_path);
257 if let Some(params) = ¶ms {
258 let mut query_pairs = request_url.query_pairs_mut();
259 if let Some(tag) = params.tag {
260 query_pairs.append_pair("tag", tag);
261 }
262 if let Some(all) = params.all {
263 query_pairs.append_pair("all", &all.to_string());
264 }
265 if let Some(compress) = params.compress {
266 query_pairs.append_pair("compress", &compress.to_string());
267 }
268 if let Some(destination) = params.destination {
269 query_pairs.append_pair("destination", destination);
270 }
271 if let Some(x_registry_auth) = params.x_registry_auth {
272 req_builder = req_builder.header("X-Registry-Auth", x_registry_auth);
273 }
274 }
275 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
276 req_builder = req_builder.uri(hyper_uri);
277 Ok(req_builder.body(String::new())?)
278 },
279 ))
280 }
281 fn image_tag<'a>(
287 &'a self,
288 name: &'a str,
289 params: Option<crate::v4::params::ImageTag<'a>>,
290 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
291 Box::pin(request::execute_request_unit(
292 self.get_config(),
293 move |mut req_builder: Builder| {
294 req_builder = req_builder.method("POST");
295 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
296 let mut request_path = request_url.path().to_owned();
297 if request_path.ends_with('/') {
298 request_path.pop();
299 }
300 request_path.push_str("/images/{name}/tag");
301 request_path = request_path.replace("{name}", name);
302 request_url.set_path(&request_path);
303 if let Some(params) = ¶ms {
304 let mut query_pairs = request_url.query_pairs_mut();
305 if let Some(repo) = params.repo {
306 query_pairs.append_pair("repo", repo);
307 }
308 if let Some(tag) = params.tag {
309 query_pairs.append_pair("tag", tag);
310 }
311 }
312 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
313 req_builder = req_builder.uri(hyper_uri);
314 Ok(req_builder.body(String::new())?)
315 },
316 ))
317 }
318 fn image_create<'a>(
324 &'a self,
325 params: Option<crate::v4::params::ImageCreate<'a>>,
326 input_image: String,
327 ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'a>> {
328 Box::pin(request::execute_request_json(
329 self.get_config(),
330 move |mut req_builder: Builder| {
331 req_builder = req_builder.method("POST");
332 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
333 let mut request_path = request_url.path().to_owned();
334 if request_path.ends_with('/') {
335 request_path.pop();
336 }
337 request_path.push_str("/images/create");
338 request_url.set_path(&request_path);
339 if let Some(params) = ¶ms {
340 let mut query_pairs = request_url.query_pairs_mut();
341 if let Some(from_image) = params.from_image {
342 query_pairs.append_pair("fromImage", from_image);
343 }
344 if let Some(from_src) = params.from_src {
345 query_pairs.append_pair("fromSrc", from_src);
346 }
347 if let Some(repo) = params.repo {
348 query_pairs.append_pair("repo", repo);
349 }
350 if let Some(tag) = params.tag {
351 query_pairs.append_pair("tag", tag);
352 }
353 if let Some(message) = params.message {
354 query_pairs.append_pair("message", message);
355 }
356 if let Some(platform) = params.platform {
357 query_pairs.append_pair("platform", platform);
358 }
359 if let Some(x_registry_auth) = params.x_registry_auth {
360 req_builder = req_builder.header("X-Registry-Auth", x_registry_auth);
361 }
362 }
363 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
364 req_builder = req_builder.uri(hyper_uri);
365 let body = serde_json::to_string(&input_image)?;
366 req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
367 req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
368 Ok(req_builder.body(body)?)
369 },
370 ))
371 }
372 fn image_get_all<'a>(
378 &'a self,
379 params: Option<crate::v4::params::ImageGetAll<'a>>,
380 ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'a>> {
381 Box::pin(request::execute_request_json(
382 self.get_config(),
383 move |mut req_builder: Builder| {
384 req_builder = req_builder.method("GET");
385 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
386 let mut request_path = request_url.path().to_owned();
387 if request_path.ends_with('/') {
388 request_path.pop();
389 }
390 request_path.push_str("/images/get");
391 request_url.set_path(&request_path);
392 if let Some(params) = ¶ms {
393 let mut query_pairs = request_url.query_pairs_mut();
394 query_pairs.append_pair("names", params.names);
395 }
396 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
397 req_builder = req_builder.uri(hyper_uri);
398 Ok(req_builder.body(String::new())?)
399 },
400 ))
401 }
402 fn image_list<'a>(
408 &'a self,
409 params: Option<crate::v4::params::ImageList<'a>>,
410 ) -> Pin<Box<dyn Future<Output = Result<Vec<()>, Error>> + Send + 'a>> {
411 Box::pin(request::execute_request_json(
412 self.get_config(),
413 move |mut req_builder: Builder| {
414 req_builder = req_builder.method("GET");
415 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
416 let mut request_path = request_url.path().to_owned();
417 if request_path.ends_with('/') {
418 request_path.pop();
419 }
420 request_path.push_str("/images/json");
421 request_url.set_path(&request_path);
422 if let Some(params) = ¶ms {
423 let mut query_pairs = request_url.query_pairs_mut();
424 if let Some(all) = params.all {
425 query_pairs.append_pair("all", &all.to_string());
426 }
427 if let Some(filters) = params.filters {
428 query_pairs.append_pair("filters", filters);
429 }
430 if let Some(digests) = params.digests {
431 query_pairs.append_pair("digests", &digests.to_string());
432 }
433 }
434 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
435 req_builder = req_builder.uri(hyper_uri);
436 Ok(req_builder.body(String::new())?)
437 },
438 ))
439 }
440 fn image_load<'a>(
446 &'a self,
447 params: Option<crate::v4::params::ImageLoad>,
448 request: String,
449 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
450 Box::pin(request::execute_request_unit(
451 self.get_config(),
452 move |mut req_builder: Builder| {
453 req_builder = req_builder.method("POST");
454 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
455 let mut request_path = request_url.path().to_owned();
456 if request_path.ends_with('/') {
457 request_path.pop();
458 }
459 request_path.push_str("/images/load");
460 request_url.set_path(&request_path);
461 if let Some(params) = ¶ms {
462 let mut query_pairs = request_url.query_pairs_mut();
463 if let Some(quiet) = params.quiet {
464 query_pairs.append_pair("quiet", &quiet.to_string());
465 }
466 }
467 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
468 req_builder = req_builder.uri(hyper_uri);
469 let body = serde_json::to_string(&request)?;
470 req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
471 req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
472 Ok(req_builder.body(body)?)
473 },
474 ))
475 }
476 fn image_prune<'a>(
482 &'a self,
483 params: Option<crate::v4::params::ImagePrune<'a>>,
484 ) -> Pin<Box<dyn Future<Output = Result<Vec<()>, Error>> + Send + 'a>> {
485 Box::pin(request::execute_request_json(
486 self.get_config(),
487 move |mut req_builder: Builder| {
488 req_builder = req_builder.method("POST");
489 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
490 let mut request_path = request_url.path().to_owned();
491 if request_path.ends_with('/') {
492 request_path.pop();
493 }
494 request_path.push_str("/images/prune");
495 request_url.set_path(&request_path);
496 if let Some(params) = ¶ms {
497 let mut query_pairs = request_url.query_pairs_mut();
498 if let Some(filters) = params.filters {
499 query_pairs.append_pair("filters", filters);
500 }
501 }
502 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
503 req_builder = req_builder.uri(hyper_uri);
504 Ok(req_builder.body(String::new())?)
505 },
506 ))
507 }
508 fn image_search<'a>(
514 &'a self,
515 params: Option<crate::v4::params::ImageSearch<'a>>,
516 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
517 Box::pin(request::execute_request_unit(
518 self.get_config(),
519 move |mut req_builder: Builder| {
520 req_builder = req_builder.method("GET");
521 let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
522 let mut request_path = request_url.path().to_owned();
523 if request_path.ends_with('/') {
524 request_path.pop();
525 }
526 request_path.push_str("/images/search");
527 request_url.set_path(&request_path);
528 if let Some(params) = ¶ms {
529 let mut query_pairs = request_url.query_pairs_mut();
530 if let Some(term) = params.term {
531 query_pairs.append_pair("term", term);
532 }
533 if let Some(limit) = params.limit {
534 query_pairs.append_pair("limit", &limit.to_string());
535 }
536 if let Some(filters) = params.filters {
537 query_pairs.append_pair("filters", filters);
538 }
539 if let Some(tls_verify) = params.tls_verify {
540 query_pairs.append_pair("tlsVerify", &tls_verify.to_string());
541 }
542 if let Some(list_tags) = params.list_tags {
543 query_pairs.append_pair("listTags", &list_tags.to_string());
544 }
545 }
546 let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
547 req_builder = req_builder.uri(hyper_uri);
548 Ok(req_builder.body(String::new())?)
549 },
550 ))
551 }
552}