docker_api/api/
plugin.rs

1//! Install, create and manage plugins
2
3use crate::{
4    conn::{Headers, Payload},
5    models,
6    opts::PluginListOpts,
7    Result,
8};
9use containers_api::url::{construct_ep, encoded_pair};
10
11use std::path::Path;
12
13impl_api_ty!(Plugin => name);
14
15impl Plugin {
16    impl_api_ep! {plug: Plugin, resp
17        Inspect -> &format!("/plugins/{}/json", plug.name), models::Plugin
18        ForceDelete -> &format!("/plugins/{}", plug.name), models::Plugin
19    }
20
21    api_doc! { Plugin => Enable
22    |
23    /// Enable a plugin.
24    pub async fn enable(&self, timeout: Option<u64>) -> Result<()> {
25        let query = timeout.map(|timeout| encoded_pair("timeout", timeout));
26        self.docker
27            .post(
28                &construct_ep(format!("/plugins/{}/enable", self.name), query),
29                Payload::empty(),
30                Headers::none()
31            )
32            .await
33            .map(|_| ())
34    }}
35
36    api_doc! { Plugin => Disable
37    |
38    /// Disable a plugin.
39    pub async fn disable(&self) -> Result<()> {
40        self.docker
41            .post(&format!("/plugins/{}/disable", self.name), Payload::empty(), Headers::none())
42            .await
43            .map(|_| ())
44    }}
45
46    api_doc! { Plugin => Push
47    |
48    /// Push a plugin to the registry.
49    pub async fn push(&self) -> Result<()> {
50        self.docker
51            .post(&format!("/plugins/{}/push", self.name), Payload::empty(), Headers::none())
52            .await
53            .map(|_| ())
54    }}
55
56    api_doc! { Plugin => Create
57    |
58    /// Create a plugin from a tar archive on the file system. The `path` parameter is a path
59    /// to the tar containing plugin rootfs and manifest.
60    pub async fn create<P>(&self, path: P) -> Result<()>
61    where
62        P: AsRef<Path>,
63    {
64        self.docker
65            .post(
66                &format!("/plugins/{}/create", self.name),
67                Payload::Text(path.as_ref().to_string_lossy().to_string()),
68                Headers::none()
69            )
70            .await
71            .map(|_| ())
72    }}
73}
74
75impl Plugins {
76    impl_api_ep! {plug: Plugin, resp
77        List -> "/plugins", models::Plugin
78    }
79}