Skip to main content

helm_rs/command/
plugin.rs

1use std::path::PathBuf;
2
3use super::builder_collections;
4use crate::backend::Command;
5use crate::options::Secret;
6
7/// `helm plugin install`: installs a plugin from a local directory, an archive URL, a VCS URL or
8/// an `oci://` reference.
9///
10/// Helm 4.3.0 has `--username` and `--password` for OCI sources but its OCI plugin getter ignores
11/// them (`pkg/getter/ocigetter.go` builds the registry client without basic auth), so only the
12/// username is modelled. Authenticate with [`RegistryLogin`](super::RegistryLogin), whose
13/// credentials the installer reads from `$HELM_CONFIG_HOME/registry/config.json`.
14#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
15#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
16pub struct PluginInstall {
17    /// The plugin source (`<path|url>`).
18    #[builder(start_fn)]
19    pub source: String,
20    /// Flag `--version`: a version constraint (the latest when unset).
21    pub version: Option<String>,
22    /// Flag `--verify`: verify the signature before installing. Helm's default is true; `false`
23    /// is passed as `--verify=false`. Local directories are never verified.
24    #[builder(default = true)]
25    pub verify: bool,
26    /// Flag `--keyring`: the public keyring used for verification.
27    pub keyring: Option<PathBuf>,
28    /// Flag `--cert-file`: the SSL client certificate.
29    pub cert_file: Option<PathBuf>,
30    /// Flag `--key-file`: the SSL client key.
31    pub key_file: Option<PathBuf>,
32    /// Flag `--ca-file`: the CA bundle that verifies the server.
33    pub ca_file: Option<PathBuf>,
34    /// Flag `--insecure-skip-tls-verify`: skip the TLS certificate checks.
35    pub insecure_skip_tls_verify: bool,
36    /// Flag `--plain-http`: use insecure HTTP connections.
37    pub plain_http: bool,
38    /// Flag `--username`: the registry username.
39    pub username: Option<String>,
40}
41
42impl PluginInstall {
43    /// Installs `source` with Helm's defaults (signature verification on).
44    #[must_use]
45    pub fn new(source: impl Into<String>) -> Self {
46        Self::builder(source).build()
47    }
48}
49
50impl Command for PluginInstall {
51    type Output = PluginInstalled;
52}
53
54/// What a successful `helm plugin install` printed (`pkg/cmd/plugin_install.go`, Helm v4.3.0).
55#[derive(Debug, Clone, PartialEq, Eq)]
56pub struct PluginInstalled {
57    /// The name of the installed plugin (`Installed plugin:` line).
58    pub name: String,
59    /// The signer and hash Helm verified, as `plugin verify` reports them; `None` when Helm did
60    /// not verify (a local directory, or `verify` is false).
61    pub verification: Option<PluginVerification>,
62}
63
64/// `helm plugin list`: the installed plugins. Helm has no machine output for it, so the CLI
65/// backend parses the table.
66#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
67#[builder(on(String, into))]
68pub struct PluginList {
69    /// Flag `--type`: only plugins of this type (`cli/v1`, `getter/v1`, `postrenderer/v1`).
70    pub kind: Option<String>,
71}
72
73/// One installed plugin: a row of the `helm plugin list` table (`pkg/cmd/plugin_list.go`).
74#[derive(Debug, Clone, PartialEq, Eq)]
75pub struct Plugin {
76    /// The plugin name.
77    pub name: String,
78    /// The plugin version; empty when the plugin declares none.
79    pub version: String,
80    /// The plugin type, for example `cli/v1`.
81    pub kind: String,
82    /// The plugin API version: `v1` or `legacy`.
83    pub api_version: String,
84    /// The provenance status Helm reports: `signed`, `unsigned`, `local dev`, `invalid provenance`,
85    /// `mismatched provenance` or `unknown`.
86    pub provenance: String,
87    /// The source URL; `None` when Helm prints `unknown`.
88    pub source: Option<String>,
89}
90
91impl Command for PluginList {
92    type Output = Vec<Plugin>;
93}
94
95/// Where `helm plugin package --sign` reads the passphrase of the signing key.
96#[derive(Debug, Clone, PartialEq, Eq)]
97pub enum Passphrase {
98    /// Flag `--passphrase-file`: a file that contains the passphrase.
99    File(PathBuf),
100    /// Flag `--passphrase-file -`: the passphrase, written to Helm's stdin.
101    Stdin(Secret),
102}
103
104/// `helm plugin package`: packages a plugin directory into `NAME-VERSION.tgz`, signed by default.
105#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
106#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
107pub struct PluginPackage {
108    /// The plugin directory (`PATH`).
109    #[builder(start_fn)]
110    pub path: PathBuf,
111    /// Flag `--destination` (`-d`): where to write the tarball (Helm's default is `.`).
112    pub destination: Option<PathBuf>,
113    /// Flag `--sign`: sign the plugin with a PGP key and write a `.prov` file. Helm's default is
114    /// true; `false` is passed as `--sign=false`.
115    #[builder(default = true)]
116    pub sign: bool,
117    /// Flag `--key`: the name of the signing key.
118    pub key: Option<String>,
119    /// Flag `--keyring`: the keyring that holds the key.
120    pub keyring: Option<PathBuf>,
121    /// Flag `--passphrase-file`: the passphrase of the signing key.
122    pub passphrase: Option<Passphrase>,
123}
124
125impl PluginPackage {
126    /// Packages `path` with Helm's defaults (signing on).
127    #[must_use]
128    pub fn new(path: impl Into<PathBuf>) -> Self {
129        Self::builder(path).build()
130    }
131}
132
133impl Command for PluginPackage {
134    type Output = ();
135}
136
137/// `helm plugin uninstall`: removes installed plugins.
138#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
139#[builder(start_fn(name = start, vis = ""))]
140pub struct PluginUninstall {
141    /// The plugin names (`<plugin>...`); at least one.
142    #[builder(field)]
143    pub names: Vec<String>,
144}
145
146builder_collections! {
147    PluginUninstallBuilder, plugin_uninstall_builder;
148    vec names / name: String, "`<plugin>` arguments", "the names of the plugins";
149}
150
151impl PluginUninstall {
152    /// Starts building for the plugins in `names`, the first of the required `<plugin>...`.
153    pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> PluginUninstallBuilder {
154        Self::start().names(names)
155    }
156
157    /// Uninstalls the named plugins.
158    #[must_use]
159    pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
160        Self::builder(names).build()
161    }
162}
163
164impl Command for PluginUninstall {
165    type Output = ();
166}
167
168/// `helm plugin update`: updates installed plugins from their source.
169#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
170#[builder(start_fn(name = start, vis = ""))]
171pub struct PluginUpdate {
172    /// The plugin names (`<plugin>...`); at least one.
173    #[builder(field)]
174    pub names: Vec<String>,
175}
176
177builder_collections! {
178    PluginUpdateBuilder, plugin_update_builder;
179    vec names / name: String, "`<plugin>` arguments", "the names of the plugins";
180}
181
182impl PluginUpdate {
183    /// Starts building for the plugins in `names`, the first of the required `<plugin>...`.
184    pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> PluginUpdateBuilder {
185        Self::start().names(names)
186    }
187
188    /// Updates the named plugins.
189    #[must_use]
190    pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
191        Self::builder(names).build()
192    }
193}
194
195impl Command for PluginUpdate {
196    type Output = ();
197}
198
199/// What a successful `helm plugin verify` reports (`pkg/cmd/plugin_verify.go`, Helm v4.3.0).
200#[derive(Debug, Clone, PartialEq, Eq)]
201pub struct PluginVerification {
202    /// The identities of the signing key (`Signed by:` lines), for example `Name <mail>`.
203    pub signed_by: Vec<String>,
204    /// The fingerprint of the signing key, upper-case hex.
205    pub fingerprint: String,
206    /// The verified tarball hash, for example `sha256:...`.
207    pub hash: String,
208}
209
210/// `helm plugin verify`: verifies a plugin tarball against its `.prov` file. Failure is the error;
211/// success returns the signer and the verified hash.
212#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
213#[builder(on(PathBuf, into))]
214pub struct PluginVerify {
215    /// The plugin tarball (`PATH`); `PATH.prov` must sit next to it.
216    #[builder(start_fn)]
217    pub path: PathBuf,
218    /// Flag `--keyring`: the keyring that holds the public keys.
219    pub keyring: Option<PathBuf>,
220}
221
222impl PluginVerify {
223    /// Verifies the tarball at `path`.
224    #[must_use]
225    pub fn new(path: impl Into<PathBuf>) -> Self {
226        Self::builder(path).build()
227    }
228}
229
230impl Command for PluginVerify {
231    type Output = PluginVerification;
232}