stackify_docker_api/api/
config.rs

1//! Configs are application configurations that can be used by services.
2//! Swarm mode must be enabled for these endpoints to work.
3
4use crate::{
5    conn::{Headers, Payload},
6    models,
7    opts::{ConfigCreateOpts, ConfigListOpts},
8    Result,
9};
10
11impl_api_ty!(Config => name);
12
13impl Config {
14    impl_api_ep! { cfg: Config, resp
15        Inspect -> &format!("/configs/{}", cfg.name), models::Config
16        Delete -> &format!("/configs/{}", cfg.name), ()
17    }
18
19    // TODO: add Config::update
20}
21
22impl Configs {
23    impl_api_ep! { __: Config, resp
24        List -> "/configs", models::Config
25    }
26
27    api_doc! {
28    Config => Create
29    |
30    /// Create a new config.
31    pub async fn create(&self, opts: &ConfigCreateOpts) -> Result<Config> {
32        use serde::Deserialize;
33        #[derive(Deserialize)]
34        struct ConfigCreateResponse {
35            #[serde(rename = "Id")]
36            pub id: String,
37        }
38        self.docker
39            .post_json("/configs/create", Payload::Json(opts.serialize_vec()?), Headers::none())
40            .await
41            .map(|resp: ConfigCreateResponse| {
42                Config::new(self.docker.clone(), resp.id)
43            })
44    }}
45}