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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use crate::{api::ApiResource, conn::Payload, models, opts, util::url, Result};

impl_api_ty!(
    Manifest => name
);

impl<'podman> Manifest<'podman> {
    api_doc! {
    Manifest => ExistsLibpod
    /// Quick way to determine if a manifest exists by name or id.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// match podman.manifests().get("some-manifest").exists().await {
    ///     Ok(exists) => if exists {
    ///         println!("manifest exists!");
    ///     } else {
    ///         println!("manifest doesn't exists!");
    ///     },
    ///     Err(e) => eprintln!("check failed: {}", e),
    /// }
    /// ```
    |
    pub async fn exists(&self) -> Result<bool> {
        self.podman
            .resource_exists(ApiResource::Manifests, &self.name)
            .await
    }}

    api_doc! {
    Manifest => InspectLibpod
    /// Display details about this manifest list.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// match podman.manifests().get("my-manifest").inspect().await {
    ///     Ok(info) => println!("{:?}", info),
    ///     Err(e) => eprintln!("{}", e),
    /// }
    /// ```
    |
    pub async fn inspect(&self) -> Result<models::Schema2List> {
        self.podman
            .get_json(&format!("/libpod/manifests/{}/json", &self.name))
            .await
    }}

    api_doc! {
    Manifest => AddLibpod
    /// Add an image to this manifest list.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// let manifest = podman.manifests().get("my-manifest");
    /// match manifest
    ///     .add_image(&ManifestImageAddOpts::builder().images(["centos"]).build())
    ///     .await
    /// {
    ///     Ok(id) => println!("{:?}", id),
    ///     Err(e) => eprintln!("{}", e),
    /// }
    /// ```
    |
    pub async fn add_image(&self, opts: &opts::ManifestImageAddOpts) -> Result<models::IdResponse> {
        self.podman
            .post_json(
                &format!("/libpod/manifests/{}/add", &self.name),
                Payload::Json(opts.serialize()?),
            )
            .await
    }}

    api_doc! {
    Manifest => DeleteLibpod
    /// Remove an image digest from this manifest list.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// match podman
    ///   .manifests()
    ///   .get("my-manifest")
    ///   .remove_image("sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc")
    ///   .await {
    ///     Ok(id) => println!("{:?}", id),
    ///     Err(e) => eprintln!("{}", e),
    /// }
    /// ```
    |
    pub async fn remove_image(&self, digest: impl Into<String>) -> Result<models::IdResponse> {
        let ep = url::construct_ep(
            &format!("/libpod/manifests/{}", &self.name),
            Some(url::encoded_pair("digest", digest.into())),
        );

        self.podman.delete_json(&ep).await
    }}

    api_doc! {
    Manifest => PushLibpod
    /// Push this manifest list to a registry.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// let manifest = podman.manifests().get("my-manifest");
    /// match manifest
    ///     .push(&ManifestPushOpts::builder("some-registry.addr").all(true).build())
    ///     .await
    /// {
    ///     Ok(id) => println!("{:?}", id),
    ///     Err(e) => eprintln!("{}", e),
    /// }
    /// ```
    |
    pub async fn push(&self, opts: &opts::ManifestPushOpts) -> Result<models::IdResponse> {
        let ep = url::construct_ep(
            &format!("/libpod/manifests/{}/push", &self.name),
            opts.serialize(),
        );
        self.podman.post_json(&ep, Payload::empty()).await
    }}
}

impl<'podman> Manifests<'podman> {
    api_doc! {
    Manifest => CreateLibpod
    /// Create a manifest list.
    ///
    /// Examples:
    ///
    /// ```no_run
    /// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
    ///
    /// match podman
    ///     .manifests()
    ///     .create(
    ///         &ManifestCreateOpts::builder("my-manifest")
    ///             .image("alpine")
    ///             .build(),
    ///     )
    ///     .await
    /// {
    ///     Ok(manifest) => { /* do something with the manifest */ }
    ///     Err(e) => eprintln!("{}", e),
    /// }
    /// ```
    |
    pub async fn create(&self, opts: &opts::ManifestCreateOpts) -> Result<Manifest<'_>> {
        let ep = url::construct_ep("/libpod/manifests/create", opts.serialize());
        self.podman
            .post_json(&ep, Payload::empty())
            .await
            .map(|resp: models::IdResponse| self.podman.manifests().get(resp.id))
    }}
}