rs_docker_api_rs/api/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Configs are application configurations that can be used by services.
//! Swarm mode must be enabled for these endpoints to work.

use crate::{
    conn::{Headers, Payload},
    models,
    opts::{ConfigCreateOpts, ConfigListOpts},
    Result,
};

impl_api_ty!(Config => name);

impl Config {
    impl_api_ep! { cfg: Config, resp
        Inspect -> &format!("/configs/{}", cfg.name), rs_docker_api_stubs::models::Config
        Delete -> &format!("/configs/{}", cfg.name), ()
    }

    // TODO: add Config::update
}

impl Configs {
    impl_api_ep! { __: Config, resp
        List -> "/configs", rs_docker_api_stubs::models::Config
    }

    api_doc! {
    Config => Create
    |
    /// Create a new config.
    pub async fn create(&self, opts: &ConfigCreateOpts) -> Result<Config> {
        use serde::Deserialize;
        #[derive(Deserialize)]
        struct ConfigCreateResponse {
            #[serde(rename = "Id")]
            pub id: String,
        }
        self.docker
            .post_json("/configs/create", Payload::Json(opts.serialize_vec()?), Headers::none())
            .await
            .map(|resp: ConfigCreateResponse| {
                Config::new(self.docker.clone(), resp.id)
            })
    }}
}