podman_client/pods/
kube_play.rs

1use std::collections::HashMap;
2
3use url::form_urlencoded;
4
5use crate::{
6    client::Client,
7    models::{
8        connection::SendRequestOptions,
9        lib::Error,
10        podman::pods::kube_play::{PodKubePlay, PodKubePlayOptions},
11    },
12    utils::bool_to_str::bool_to_str,
13};
14
15impl Client {
16    pub async fn pod_kube_play(
17        &self,
18        options: PodKubePlayOptions<'_>,
19    ) -> Result<PodKubePlay, Error> {
20        let mut path = "/libpod/play/kube".to_owned();
21
22        let mut query = form_urlencoded::Serializer::new(String::new());
23        if let Some(annotation) = options.annotation {
24            query.append_pair("annotation", &serde_json::to_string(&annotation)?);
25        }
26        if let Some(build) = options.build {
27            query.append_pair("build", bool_to_str(build));
28        }
29        if let Some(log_driver) = options.log_driver {
30            query.append_pair("logDriver", log_driver);
31        }
32        if let Some(log_options) = options.log_options {
33            for log_option in log_options {
34                query.append_pair("logOptions", log_option);
35            }
36        }
37        if let Some(network) = options.network {
38            for n in network {
39                query.append_pair("network", n);
40            }
41        }
42        if let Some(no_hosts) = options.no_hosts {
43            query.append_pair("noHosts", bool_to_str(no_hosts));
44        }
45        if let Some(no_trunc) = options.no_trunc {
46            query.append_pair("noTrunc", bool_to_str(no_trunc));
47        }
48        if let Some(publish_all_ports) = options.publish_all_ports {
49            query.append_pair("publishAllPorts", bool_to_str(publish_all_ports));
50        }
51        if let Some(publish_ports) = options.publish_ports {
52            for publish_port in publish_ports {
53                query.append_pair("publishPorts", publish_port);
54            }
55        }
56        if let Some(replace) = options.replace {
57            query.append_pair("replace", bool_to_str(replace));
58        }
59        if let Some(service_container) = options.service_container {
60            query.append_pair("serviceContainer", bool_to_str(service_container));
61        }
62        if let Some(start) = options.start {
63            query.append_pair("start", bool_to_str(start));
64        }
65        if let Some(static_ips) = options.static_ips {
66            for static_ip in static_ips {
67                query.append_pair("staticIPs", static_ip);
68            }
69        }
70        if let Some(static_macs) = options.static_macs {
71            for static_mac in static_macs {
72                query.append_pair("staticMACs", static_mac);
73            }
74        }
75        if let Some(tls_verify) = options.tls_verify {
76            query.append_pair("tlsVerify", bool_to_str(tls_verify));
77        }
78        if let Some(userns) = options.userns {
79            query.append_pair("userns", userns);
80        }
81        if let Some(wait) = options.wait {
82            query.append_pair("wait", bool_to_str(wait));
83        }
84        let query_string = query.finish();
85        if !query_string.is_empty() {
86            path += &["?", &query_string].concat();
87        }
88
89        let (_, data) = self
90            .send_request::<_, (), _>(SendRequestOptions {
91                method: "POST",
92                path: &path,
93                header: Some(HashMap::from([("Content-Type", "plain/text")])),
94                body: options.kubernetes_yaml_file,
95            })
96            .await?;
97
98        Ok(data)
99    }
100}