podman_client/secrets/
list.rs

1use 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::secrets::list::{SecretList, SecretListOptions},
13    },
14};
15
16impl Client {
17    pub async fn secret_list(
18        &self,
19        options: Option<SecretListOptions<'_>>,
20    ) -> Result<SecretList, Error> {
21        let mut path = "/libpod/secrets/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(name) = opt_filters.name
28                && !name.is_empty()
29            {
30                filters.insert("name", name);
31            }
32            if let Some(id) = opt_filters.id
33                && !id.is_empty()
34            {
35                filters.insert("id", id);
36            }
37
38            if !filters.is_empty() {
39                let filters_json = serde_json::to_string(&filters)?;
40                let filters_encoded: String = byte_serialize(filters_json.as_bytes()).collect();
41                path += &["?filters=", &filters_encoded].concat();
42            }
43        }
44
45        let (_, data) = self
46            .send_request::<_, (), _>(SendRequestOptions {
47                method: "GET",
48                path: &path,
49                header: None,
50                body: Empty::<Bytes>::new(),
51            })
52            .await?;
53
54        Ok(data)
55    }
56}