Skip to main content

helm_rs/command/render/
package.rs

1use std::path::PathBuf;
2
3use crate::backend::Command;
4use crate::command::Passphrase;
5use crate::command::builder_collections;
6use crate::options::Secret;
7
8/// `helm package` (`pkg/cmd/package.go`, `pkg/action/package.go`): packages chart directories
9/// into `NAME-VERSION.tgz` archives and returns the path of each, in order.
10///
11/// Helm hands `--username` and `--password` only to its registry client, which downloads the
12/// `oci://` dependencies of `--dependency-update`. The password never reaches argv: the CLI backend
13/// writes it to a `0600` temporary registry config with an entry for every `oci://` host the
14/// charts declare, and refuses a password when the charts have no `oci://` dependency.
15#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
16#[builder(start_fn(name = start, vis = ""), on(String, into), on(PathBuf, into), on(Secret, into), on(bool, default))]
17#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
18pub struct Package {
19    /// The `CHART_PATH` arguments: the chart directories; at least one.
20    #[builder(field)]
21    pub charts: Vec<PathBuf>,
22    /// Flag `--app-version`: set `appVersion` in the archive.
23    pub app_version: Option<String>,
24    /// Flag `--ca-file`: the CA bundle that verifies the dependency servers.
25    pub ca_file: Option<PathBuf>,
26    /// Flag `--cert-file`: the TLS client certificate for dependency downloads.
27    pub cert_file: Option<PathBuf>,
28    /// Flag `--dependency-update`: fetch the dependencies into `charts/` first.
29    pub dependency_update: bool,
30    /// Flag `--destination`: where to write the archives (Helm's default is the working
31    /// directory).
32    pub destination: Option<PathBuf>,
33    /// Flag `--insecure-skip-tls-verify`: skip TLS checks for dependency downloads.
34    pub insecure_skip_tls_verify: bool,
35    /// Flag `--key`: the name of the signing key; required with `sign`.
36    pub key: Option<String>,
37    /// Flag `--key-file`: the TLS client key for dependency downloads.
38    pub key_file: Option<PathBuf>,
39    /// Flag `--keyring`: the keyring that holds the signing key (Helm reads the legacy keyring
40    /// format, for example the output of `gpg --export-secret-keys`).
41    pub keyring: Option<PathBuf>,
42    /// Flag `--passphrase-file`: the passphrase of the signing key, from a file or, as a secret,
43    /// through Helm's stdin (`--passphrase-file -`). Without one Helm prompts on the terminal.
44    pub passphrase: Option<Passphrase>,
45    /// Never a flag: the password for `username` at the `oci://` dependency registries.
46    pub password: Option<Secret>,
47    /// Flag `--plain-http`: use HTTP for dependency downloads.
48    pub plain_http: bool,
49    /// Flag `--sign`: sign each archive with a PGP key and write a `.prov` file next to it.
50    pub sign: bool,
51    /// Flag `--username`: the repository username for dependency downloads.
52    pub username: Option<String>,
53    /// Flag `--version`: set `version` in the archive.
54    pub version: Option<String>,
55}
56
57builder_collections! {
58    PackageBuilder, package_builder;
59    vec charts / chart: PathBuf, "`CHART_PATH` arguments", "the chart directories to package";
60}
61
62impl Package {
63    /// Starts building a package of the chart at `chart`, the first of the required
64    /// `CHART_PATH...`.
65    pub fn builder(chart: impl Into<PathBuf>) -> PackageBuilder {
66        Self::start().chart(chart)
67    }
68
69    /// Packages `chart` with Helm's defaults (unsigned, into the working directory).
70    #[must_use]
71    pub fn new(chart: impl Into<PathBuf>) -> Self {
72        Self::builder(chart).build()
73    }
74}
75
76impl Command for Package {
77    type Output = Vec<PathBuf>;
78}