podman_rest_client/v4/apis/
system_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 SystemCompat: HasConfig + Send + Sync {
8    /// POST /auth
9    ///
10    /// Check auth configuration
11    fn system_auth<'a>(
12        &'a self,
13        auth_config: (),
14    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
15        Box::pin(request::execute_request_unit(
16            self.get_config(),
17            move |mut req_builder: Builder| {
18                req_builder = req_builder.method("POST");
19                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
20                let mut request_path = request_url.path().to_owned();
21                if request_path.ends_with('/') {
22                    request_path.pop();
23                }
24                request_path.push_str("/auth");
25                request_url.set_path(&request_path);
26                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
27                req_builder = req_builder.uri(hyper_uri);
28                let body = serde_json::to_string(&auth_config)?;
29                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
30                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
31                Ok(req_builder.body(body)?)
32            },
33        ))
34    }
35    /// GET /events
36    ///
37    /// Get events
38    ///
39    /// Returns events filtered on query parameters
40    fn system_events<'a>(
41        &'a self,
42        params: Option<crate::v4::params::SystemEvents<'a>>,
43    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
44        Box::pin(request::execute_request_unit(
45            self.get_config(),
46            move |mut req_builder: Builder| {
47                req_builder = req_builder.method("GET");
48                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
49                let mut request_path = request_url.path().to_owned();
50                if request_path.ends_with('/') {
51                    request_path.pop();
52                }
53                request_path.push_str("/events");
54                request_url.set_path(&request_path);
55                if let Some(params) = &params {
56                    let mut query_pairs = request_url.query_pairs_mut();
57                    if let Some(since) = params.since {
58                        query_pairs.append_pair("since", since);
59                    }
60                    if let Some(until) = params.until {
61                        query_pairs.append_pair("until", until);
62                    }
63                    if let Some(filters) = params.filters {
64                        query_pairs.append_pair("filters", filters);
65                    }
66                }
67                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
68                req_builder = req_builder.uri(hyper_uri);
69                Ok(req_builder.body(String::new())?)
70            },
71        ))
72    }
73    /// GET /info
74    ///
75    /// Get info
76    ///
77    /// Returns information on the system and libpod configuration
78    fn system_info<'a>(&'a self) -> 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("GET");
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("/info");
89                request_url.set_path(&request_path);
90                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
91                req_builder = req_builder.uri(hyper_uri);
92                Ok(req_builder.body(String::new())?)
93            },
94        ))
95    }
96    /// GET /libpod/_ping
97    ///
98    /// Ping service
99    ///
100    /// Return protocol information in response headers.
101    /// `HEAD /libpod/_ping` is also supported.
102    /// `/_ping` is available for compatibility with other engines.
103    /// The '_ping' endpoints are not versioned.
104    fn system_ping<'a>(
105        &'a self,
106    ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'a>> {
107        Box::pin(request::execute_request_text(
108            self.get_config(),
109            move |mut req_builder: Builder| {
110                req_builder = req_builder.method("GET");
111                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
112                let mut request_path = request_url.path().to_owned();
113                if request_path.ends_with('/') {
114                    request_path.pop();
115                }
116                request_path.push_str("/libpod/_ping");
117                request_url.set_path(&request_path);
118                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
119                req_builder = req_builder.uri(hyper_uri);
120                Ok(req_builder.body(String::new())?)
121            },
122        ))
123    }
124    /// GET /system/df
125    ///
126    /// Show disk usage
127    ///
128    /// Return information about disk usage for containers, images, and volumes
129    fn system_data_usage<'a>(
130        &'a self,
131    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
132        Box::pin(request::execute_request_unit(
133            self.get_config(),
134            move |mut req_builder: Builder| {
135                req_builder = req_builder.method("GET");
136                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
137                let mut request_path = request_url.path().to_owned();
138                if request_path.ends_with('/') {
139                    request_path.pop();
140                }
141                request_path.push_str("/system/df");
142                request_url.set_path(&request_path);
143                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
144                req_builder = req_builder.uri(hyper_uri);
145                Ok(req_builder.body(String::new())?)
146            },
147        ))
148    }
149    /// GET /version
150    ///
151    /// Component Version information
152    fn system_version<'a>(
153        &'a self,
154    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
155        Box::pin(request::execute_request_unit(
156            self.get_config(),
157            move |mut req_builder: Builder| {
158                req_builder = req_builder.method("GET");
159                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
160                let mut request_path = request_url.path().to_owned();
161                if request_path.ends_with('/') {
162                    request_path.pop();
163                }
164                request_path.push_str("/version");
165                request_url.set_path(&request_path);
166                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
167                req_builder = req_builder.uri(hyper_uri);
168                Ok(req_builder.body(String::new())?)
169            },
170        ))
171    }
172}