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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Install, create and manage plugins

use crate::{conn::Payload, models, opts::PluginListOpts, Result};
use containers_api::url::{construct_ep, encoded_pair};

use std::path::Path;

impl_api_ty!(Plugin => name);

impl Plugin {
    impl_api_ep! {plug: Plugin, resp
        Inspect -> &format!("/plugins/{}/json", plug.name), models::Plugin
        ForceDelete -> &format!("/plugins/{}", plug.name), models::Plugin
    }

    api_doc! { Plugin => Enable
    /// Enable a plugin.
    |
    pub async fn enable(&self, timeout: Option<u64>) -> Result<()> {
        let query = timeout.map(|timeout| encoded_pair("timeout", timeout));
        self.docker
            .post(
                &construct_ep(format!("/plugins/{}/enable", self.name), query),
                Payload::empty(),
            )
            .await
            .map(|_| ())
    }}

    api_doc! { Plugin => Disable
    /// Disable a plugin.
    |
    pub async fn disable(&self) -> Result<()> {
        self.docker
            .post(&format!("/plugins/{}/disable", self.name), Payload::empty())
            .await
            .map(|_| ())
    }}

    api_doc! { Plugin => Push
    /// Push a plugin to the registry.
    |
    pub async fn push(&self) -> Result<()> {
        self.docker
            .post(&format!("/plugins/{}/push", self.name), Payload::empty())
            .await
            .map(|_| ())
    }}

    api_doc! { Plugin => Create
    /// Create a plugin from a tar archive on the file system. The `path` parameter is a path
    /// to the tar containing plugin rootfs and manifest.
    |
    pub async fn create<P>(&self, path: P) -> Result<()>
    where
        P: AsRef<Path>,
    {
        self.docker
            .post(
                &format!("/plugins/{}/create", self.name),
                Payload::Text(path.as_ref().to_string_lossy().to_string()),
            )
            .await
            .map(|_| ())
    }}
}

impl Plugins {
    impl_api_ep! {plug: Plugin, resp
        List -> "/plugins", models::Plugin
    }
}