podman_api/api/
secrets.rs

1use crate::{models, opts, Result};
2
3use containers_api::url;
4
5impl_api_ty!(
6    Secret => id
7);
8
9impl Secret {
10    api_doc! {
11    Secret => InspectLibpod
12    |
13    /// Inspect this secret returning detailed information about it.
14    ///
15    /// Examples:
16    ///
17    /// ```no_run
18    /// async {
19    ///     use podman_api::Podman;
20    ///     let podman = Podman::unix("/run/user/1000/podman/podman.sock");
21    ///
22    ///     match podman.secrets().get("79c93f220e3e").inspect().await {
23    ///         Ok(info) => println!("{:?}", info),
24    ///         Err(e) => eprintln!("{}", e),
25    ///     }
26    /// };
27    /// ```
28    pub async fn inspect(&self) -> Result<models::SecretInfoReport> {
29        self.podman
30            .get_json(&format!("/libpod/secrets/{}/json", &self.id))
31            .await
32    }}
33
34    api_doc! {
35    Secret => DeleteLibpod
36    |
37    /// Remove this secret
38    ///
39    /// Examples:
40    ///
41    /// ```no_run
42    /// async {
43    ///     use podman_api::Podman;
44    ///     let podman = Podman::unix("/run/user/1000/podman/podman.sock");
45    ///
46    ///     if let Err(e) = podman.secrets().get("79c93f220e3e").delete().await {
47    ///         eprintln!("{}", e);
48    ///     }
49    /// };
50    /// ```
51    pub async fn delete(&self) -> Result<()> {
52        self.podman
53            .delete(&format!("/libpod/secrets/{}", &self.id))
54            .await
55            .map(|_| ())
56    }}
57}
58
59impl Secrets {
60    api_doc! {
61    Secret => ListLibpod
62    |
63    /// List available secrets.
64    ///
65    /// Examples:
66    ///
67    /// ```no_run
68    /// async {
69    ///     use podman_api::Podman;
70    ///     let podman = Podman::unix("/run/user/1000/podman/podman.sock");
71    ///
72    ///     match podman.secrets().list().await {
73    ///         Ok(info) => println!("{:?}", info),
74    ///         Err(e) => eprintln!("{}", e),
75    ///     }
76    /// };
77    /// ```
78    pub async fn list(&self) -> Result<Vec<models::SecretInfoReport>> {
79        self.podman.get_json("/libpod/secrets/json").await
80    }}
81
82    api_doc! {
83    Secret => CreateLibpod
84    |
85    /// Create a new secret.
86    ///
87    /// Examples:
88    ///
89    /// ```no_run
90    /// async {
91    ///     use podman_api::Podman;
92    ///     use podman_api::opts::SecretCreateOpts;
93    ///     let podman = Podman::unix("/run/user/1000/podman/podman.sock");
94    ///
95    ///     match podman.secrets().create(
96    ///         &SecretCreateOpts::builder("my-secret").build(),
97    ///         "secret-value"
98    ///     ).await {
99    ///         Ok(info) => println!("{:?}", info),
100    ///         Err(e) => eprintln!("{}", e),
101    ///     }
102    /// };
103    /// ```
104    pub async fn create(
105        &self,
106        opts: &opts::SecretCreateOpts,
107        secret: impl Into<String>,
108    ) -> Result<Secret> {
109        let ep = url::construct_ep("/libpod/secrets/create", opts.serialize());
110        self.podman
111            .post_json(
112                &ep,
113                crate::conn::Payload::Json(serde_json::to_string(&secret.into())?),
114                crate::conn::Headers::none(),
115            )
116            .await
117            .map(|resp: models::SecretCreateResponse| {
118                Secret::new(self.podman.clone(), resp.id.unwrap_or_default())
119            })
120    }}
121}