podman_rest_client/v4/apis/
exec_compat.rs

1use 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 ExecCompat: HasConfig + Send + Sync {
8    /// POST /containers/{name}/exec
9    ///
10    /// Create an exec instance
11    ///
12    /// Create an exec session to run a command inside a running container. Exec sessions will be automatically removed 5 minutes after they exit.
13    fn container_exec<'a>(
14        &'a self,
15        name: &'a str,
16        control: crate::v4::models::ContainerExecBody,
17    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
18        Box::pin(request::execute_request_unit(
19            self.get_config(),
20            move |mut req_builder: Builder| {
21                req_builder = req_builder.method("POST");
22                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
23                let mut request_path = request_url.path().to_owned();
24                if request_path.ends_with('/') {
25                    request_path.pop();
26                }
27                request_path.push_str("/containers/{name}/exec");
28                request_path = request_path.replace("{name}", name);
29                request_url.set_path(&request_path);
30                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
31                req_builder = req_builder.uri(hyper_uri);
32                let body = serde_json::to_string(&control)?;
33                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
34                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
35                Ok(req_builder.body(body)?)
36            },
37        ))
38    }
39    /// GET /exec/{id}/json
40    ///
41    /// Inspect an exec instance
42    ///
43    /// Return low-level information about an exec instance.
44    fn exec_inspect<'a>(
45        &'a self,
46        id: &'a str,
47    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
48        Box::pin(request::execute_request_unit(
49            self.get_config(),
50            move |mut req_builder: Builder| {
51                req_builder = req_builder.method("GET");
52                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
53                let mut request_path = request_url.path().to_owned();
54                if request_path.ends_with('/') {
55                    request_path.pop();
56                }
57                request_path.push_str("/exec/{id}/json");
58                request_path = request_path.replace("{id}", id);
59                request_url.set_path(&request_path);
60                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
61                req_builder = req_builder.uri(hyper_uri);
62                Ok(req_builder.body(String::new())?)
63            },
64        ))
65    }
66    /// POST /exec/{id}/resize
67    ///
68    /// Resize an exec instance
69    ///
70    /// Resize the TTY session used by an exec instance. This endpoint only works if tty was specified as part of creating and starting the exec instance.
71    fn exec_resize<'a>(
72        &'a self,
73        id: &'a str,
74        params: Option<crate::v4::params::ExecResize>,
75    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
76        Box::pin(request::execute_request_unit(
77            self.get_config(),
78            move |mut req_builder: Builder| {
79                req_builder = req_builder.method("POST");
80                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
81                let mut request_path = request_url.path().to_owned();
82                if request_path.ends_with('/') {
83                    request_path.pop();
84                }
85                request_path.push_str("/exec/{id}/resize");
86                request_path = request_path.replace("{id}", id);
87                request_url.set_path(&request_path);
88                if let Some(params) = &params {
89                    let mut query_pairs = request_url.query_pairs_mut();
90                    if let Some(h) = params.h {
91                        query_pairs.append_pair("h", &h.to_string());
92                    }
93                    if let Some(w) = params.w {
94                        query_pairs.append_pair("w", &w.to_string());
95                    }
96                    if let Some(running) = params.running {
97                        query_pairs.append_pair("running", &running.to_string());
98                    }
99                }
100                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
101                req_builder = req_builder.uri(hyper_uri);
102                Ok(req_builder.body(String::new())?)
103            },
104        ))
105    }
106    /// POST /exec/{id}/start
107    ///
108    /// Start an exec instance
109    ///
110    /// Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command. Otherwise, it sets up an interactive session with the command.
111    fn exec_start<'a>(
112        &'a self,
113        id: &'a str,
114        control: crate::v4::models::ExecStartBody,
115    ) -> Pin<Box<dyn Future<Output = Result<bytes::Bytes, Error>> + Send + 'a>> {
116        Box::pin(request::execute_request_json(
117            self.get_config(),
118            move |mut req_builder: Builder| {
119                req_builder = req_builder.method("POST");
120                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
121                let mut request_path = request_url.path().to_owned();
122                if request_path.ends_with('/') {
123                    request_path.pop();
124                }
125                request_path.push_str("/exec/{id}/start");
126                request_path = request_path.replace("{id}", id);
127                request_url.set_path(&request_path);
128                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
129                req_builder = req_builder.uri(hyper_uri);
130                let body = serde_json::to_string(&control)?;
131                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
132                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
133                Ok(req_builder.body(body)?)
134            },
135        ))
136    }
137}