podman_client/volumes/
list.rs1use std::collections::HashMap;
2
3use http_body_util::Empty;
4use hyper::body::Bytes;
5use url::form_urlencoded::byte_serialize;
6
7use crate::{
8 client::Client,
9 models::{
10 connection::SendRequestOptions,
11 lib::Error,
12 podman::volumes::list::{VolumeList, VolumeListOptions},
13 },
14};
15
16impl Client {
17 pub async fn volume_list(
18 &self,
19 options: Option<VolumeListOptions<'_>>,
20 ) -> Result<VolumeList, Error> {
21 let mut path = "/libpod/volumes/json".to_owned();
22
23 if let Some(options) = options
24 && let Some(opt_filters) = options.filters
25 {
26 let mut filters = HashMap::new();
27 if let Some(driver) = opt_filters.driver
28 && !driver.is_empty()
29 {
30 filters.insert("driver", driver);
31 }
32 if let Some(label) = opt_filters.label
33 && !label.is_empty()
34 {
35 filters.insert("label", label);
36 }
37 if let Some(name) = opt_filters.name
38 && !name.is_empty()
39 {
40 filters.insert("name", name);
41 }
42 if let Some(opt) = opt_filters.opt
43 && !opt.is_empty()
44 {
45 filters.insert("opt", opt);
46 }
47 if let Some(until) = opt_filters.until
48 && !until.is_empty()
49 {
50 filters.insert("until", until);
51 }
52
53 if !filters.is_empty() {
54 let filters_json = serde_json::to_string(&filters)?;
55 let filters_encoded: String = byte_serialize(filters_json.as_bytes()).collect();
56 path += &["?filters=", &filters_encoded].concat();
57 }
58 }
59
60 let (_, data) = self
61 .send_request::<_, (), _>(SendRequestOptions {
62 method: "GET",
63 path: &path,
64 header: None,
65 body: Empty::<Bytes>::new(),
66 })
67 .await?;
68
69 Ok(data)
70 }
71}