helm-rs 0.1.0

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use std::path::PathBuf;

use crate::backend::Command;
use crate::command::Passphrase;
use crate::command::builder_collections;
use crate::options::Secret;

/// `helm package` (`pkg/cmd/package.go`, `pkg/action/package.go`): packages chart directories
/// into `NAME-VERSION.tgz` archives and returns the path of each, in order.
///
/// Helm hands `--username` and `--password` only to its registry client, which downloads the
/// `oci://` dependencies of `--dependency-update`. The password never reaches argv: the CLI backend
/// writes it to a `0600` temporary registry config with an entry for every `oci://` host the
/// charts declare, and refuses a password when the charts have no `oci://` dependency.
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(start_fn(name = start, vis = ""), on(String, into), on(PathBuf, into), on(Secret, into), on(bool, default))]
#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
pub struct Package {
    /// The `CHART_PATH` arguments: the chart directories; at least one.
    #[builder(field)]
    pub charts: Vec<PathBuf>,
    /// Flag `--app-version`: set `appVersion` in the archive.
    pub app_version: Option<String>,
    /// Flag `--ca-file`: the CA bundle that verifies the dependency servers.
    pub ca_file: Option<PathBuf>,
    /// Flag `--cert-file`: the TLS client certificate for dependency downloads.
    pub cert_file: Option<PathBuf>,
    /// Flag `--dependency-update`: fetch the dependencies into `charts/` first.
    pub dependency_update: bool,
    /// Flag `--destination`: where to write the archives (Helm's default is the working
    /// directory).
    pub destination: Option<PathBuf>,
    /// Flag `--insecure-skip-tls-verify`: skip TLS checks for dependency downloads.
    pub insecure_skip_tls_verify: bool,
    /// Flag `--key`: the name of the signing key; required with `sign`.
    pub key: Option<String>,
    /// Flag `--key-file`: the TLS client key for dependency downloads.
    pub key_file: Option<PathBuf>,
    /// Flag `--keyring`: the keyring that holds the signing key (Helm reads the legacy keyring
    /// format, for example the output of `gpg --export-secret-keys`).
    pub keyring: Option<PathBuf>,
    /// Flag `--passphrase-file`: the passphrase of the signing key, from a file or, as a secret,
    /// through Helm's stdin (`--passphrase-file -`). Without one Helm prompts on the terminal.
    pub passphrase: Option<Passphrase>,
    /// Never a flag: the password for `username` at the `oci://` dependency registries.
    pub password: Option<Secret>,
    /// Flag `--plain-http`: use HTTP for dependency downloads.
    pub plain_http: bool,
    /// Flag `--sign`: sign each archive with a PGP key and write a `.prov` file next to it.
    pub sign: bool,
    /// Flag `--username`: the repository username for dependency downloads.
    pub username: Option<String>,
    /// Flag `--version`: set `version` in the archive.
    pub version: Option<String>,
}

builder_collections! {
    PackageBuilder, package_builder;
    vec charts / chart: PathBuf, "`CHART_PATH` arguments", "the chart directories to package";
}

impl Package {
    /// Starts building a package of the chart at `chart`, the first of the required
    /// `CHART_PATH...`.
    pub fn builder(chart: impl Into<PathBuf>) -> PackageBuilder {
        Self::start().chart(chart)
    }

    /// Packages `chart` with Helm's defaults (unsigned, into the working directory).
    #[must_use]
    pub fn new(chart: impl Into<PathBuf>) -> Self {
        Self::builder(chart).build()
    }
}

impl Command for Package {
    type Output = Vec<PathBuf>;
}