podman_rest_client/v5/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::v5::models::ContainerExecBody,
17    ) -> Pin<Box<dyn Future<Output = Result<crate::v5::models::ContainerExec201, 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("/containers/{name}/exec");
29                request_path = request_path.replace("{name}", name);
30                request_url.set_path(&request_path);
31                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
32                req_builder = req_builder.uri(hyper_uri);
33                let body = serde_json::to_string(&control)?;
34                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
35                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
36                Ok(req_builder.body(body)?)
37            },
38        ))
39    }
40    /// GET /exec/{id}/json
41    ///
42    /// Inspect an exec instance
43    ///
44    /// Return low-level information about an exec instance.
45    fn exec_inspect<'a>(
46        &'a self,
47        id: &'a str,
48    ) -> Pin<
49        Box<dyn Future<Output = Result<crate::v5::models::InspectExecSession, Error>> + Send + 'a>,
50    > {
51        Box::pin(request::execute_request_json(
52            self.get_config(),
53            move |mut req_builder: Builder| {
54                req_builder = req_builder.method("GET");
55                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
56                let mut request_path = request_url.path().to_owned();
57                if request_path.ends_with('/') {
58                    request_path.pop();
59                }
60                request_path.push_str("/exec/{id}/json");
61                request_path = request_path.replace("{id}", id);
62                request_url.set_path(&request_path);
63                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
64                req_builder = req_builder.uri(hyper_uri);
65                Ok(req_builder.body(String::new())?)
66            },
67        ))
68    }
69    /// POST /exec/{id}/resize
70    ///
71    /// Resize an exec instance
72    ///
73    /// 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.
74    fn exec_resize<'a>(
75        &'a self,
76        id: &'a str,
77        params: Option<crate::v5::params::ExecResize>,
78    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
79        Box::pin(request::execute_request_unit(
80            self.get_config(),
81            move |mut req_builder: Builder| {
82                req_builder = req_builder.method("POST");
83                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
84                let mut request_path = request_url.path().to_owned();
85                if request_path.ends_with('/') {
86                    request_path.pop();
87                }
88                request_path.push_str("/exec/{id}/resize");
89                request_path = request_path.replace("{id}", id);
90                request_url.set_path(&request_path);
91                if let Some(params) = &params {
92                    let mut query_pairs = request_url.query_pairs_mut();
93                    if let Some(h) = params.h {
94                        query_pairs.append_pair("h", &h.to_string());
95                    }
96                    if let Some(w) = params.w {
97                        query_pairs.append_pair("w", &w.to_string());
98                    }
99                    if let Some(running) = params.running {
100                        query_pairs.append_pair("running", &running.to_string());
101                    }
102                }
103                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
104                req_builder = req_builder.uri(hyper_uri);
105                Ok(req_builder.body(String::new())?)
106            },
107        ))
108    }
109    /// POST /exec/{id}/start
110    ///
111    /// Start an exec instance
112    ///
113    /// 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.
114    fn exec_start<'a>(
115        &'a self,
116        id: &'a str,
117        control: crate::v5::models::ExecStartBody,
118    ) -> Pin<
119        Box<
120            dyn Future<Output = Result<hyper_util::rt::TokioIo<hyper::upgrade::Upgraded>, Error>>
121                + Send
122                + 'a,
123        >,
124    > {
125        Box::pin(request::execute_request_upgrade(
126            self.get_config(),
127            move |mut req_builder: Builder| {
128                req_builder = req_builder.method("POST");
129                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
130                let mut request_path = request_url.path().to_owned();
131                if request_path.ends_with('/') {
132                    request_path.pop();
133                }
134                request_path.push_str("/exec/{id}/start");
135                request_path = request_path.replace("{id}", id);
136                request_url.set_path(&request_path);
137                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
138                req_builder = req_builder.uri(hyper_uri);
139                let body = serde_json::to_string(&control)?;
140                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
141                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
142                Ok(req_builder.body(body)?)
143            },
144        ))
145    }
146}