helm-rs 0.1.1

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

use super::{ChartPathOptions, ChartRef};
use crate::backend::Command;
use crate::options::Secret;

/// What Helm verified about a chart: the signer and the hash of the archive
/// (`pkg/action/verify.go`, `pkg/action/pull.go`, Helm v4.3.0).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChartVerification {
    /// The identities of the signing key (`Signed by:` lines), for example `Name <mail>`. Helm
    /// iterates a Go map to print them, so the order is not defined.
    pub signed_by: Vec<String>,
    /// The fingerprint of the signing key, upper-case hex.
    pub fingerprint: String,
    /// The verified archive hash, for example `sha256:...`.
    pub hash: String,
}

/// A chart or provenance blob in an OCI registry, as the `Pulled:`/`Pushed:` and `Digest:` line
/// pairs of Helm's registry client name it (`pkg/registry/client.go`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RegistryArtifact {
    /// The reference without the `oci://` scheme, for example `host:5000/charts/web:1.2.3`.
    pub reference: String,
    /// The manifest digest, for example `sha256:...`.
    pub digest: String,
}

/// What a successful `helm pull` printed (`pkg/action/pull.go`, Helm v4.3.0). Helm does not
/// print where it saved the chart: that is `<destination>/<name>-<version>.tgz`, or with
/// `untar` a directory below it.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Pulled {
    /// The registry artifacts pulled, in order: the chart, then its provenance file when
    /// `--verify` or `--prov` fetched one. Empty for a chart repository or a URL.
    pub artifacts: Vec<RegistryArtifact>,
    /// The verification report, present only with `--verify`.
    pub verification: Option<ChartVerification>,
    /// The `WARNING:` lines, for example a missing provenance file with `--prov`.
    pub warnings: Vec<String>,
}

/// `helm pull`: downloads a chart from a repository, a URL or an OCI registry, and optionally
/// unpacks it. The destination directory must exist. Helm's several-charts form is a loop over
/// the charts with the same flags (`pkg/cmd/pull.go`), so this command pulls one chart; run it once
/// per chart.
#[derive(Debug, Clone, PartialEq, bon::Builder)]
#[builder(on(PathBuf, into), on(bool, default))]
pub struct Pull {
    /// The chart to download (`[chart URL | repo/chartname]`).
    #[builder(start_fn)]
    pub chart: ChartRef,
    /// The chart download flags, including `--verify` and `--keyring`.
    #[builder(default)]
    pub chart_path: ChartPathOptions,
    /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored when a
    /// version is set.
    pub devel: bool,
    /// Flag `--untar`: unpack the chart after downloading it.
    pub untar: bool,
    /// Flag `--untardir`: with `untar`, the directory the chart is expanded into (Helm's default
    /// is `.`); a relative path is joined to `destination`.
    pub untardir: Option<PathBuf>,
    /// Flag `--destination` (`-d`): where to write the chart (Helm's default is `.`).
    pub destination: Option<PathBuf>,
    /// Flag `--prov`: fetch the provenance file without verifying it.
    pub prov: bool,
}

impl Pull {
    /// Pulls `chart` with Helm's defaults.
    #[must_use]
    pub fn new(chart: ChartRef) -> Self {
        Self::builder(chart).build()
    }
}

impl Command for Pull {
    type Output = Pulled;
}

/// `helm push`: uploads a packaged chart (and its `.prov` file when it sits next to it) to an
/// OCI registry. Helm 4.3 has only the OCI pusher.
///
/// The `password` never reaches argv: the CLI backend writes it, with the username, to a `0600`
/// temporary registry config for the registry host of `remote`, like
/// [`ChartPathOptions::password`].
#[derive(Debug, Clone, PartialEq, bon::Builder)]
#[builder(
    on(String, into),
    on(PathBuf, into),
    on(Secret, into),
    on(bool, default)
)]
pub struct Push {
    /// The packaged chart (`[chart]`), a `.tgz` file.
    #[builder(start_fn)]
    pub chart: PathBuf,
    /// The registry to push to (`[remote]`), `oci://host/path`; Helm appends the chart name and
    /// version.
    #[builder(start_fn)]
    pub remote: String,
    /// Flag `--cert-file`: the registry client SSL certificate.
    pub cert_file: Option<PathBuf>,
    /// Flag `--key-file`: the registry client SSL key.
    pub key_file: Option<PathBuf>,
    /// Flag `--ca-file`: the CA bundle that verifies HTTPS servers.
    pub ca_file: Option<PathBuf>,
    /// Flag `--insecure-skip-tls-verify`.
    pub insecure_skip_tls_verify: bool,
    /// Flag `--plain-http`: use insecure HTTP connections.
    pub plain_http: bool,
    /// Flag `--username`.
    pub username: Option<String>,
    /// Never a flag: see the type documentation.
    pub password: Option<Secret>,
}

impl Push {
    /// Pushes `chart` to `remote` with Helm's defaults.
    #[must_use]
    pub fn new(chart: impl Into<PathBuf>, remote: impl Into<String>) -> Self {
        Self::builder(chart, remote).build()
    }
}

impl Command for Push {
    type Output = RegistryArtifact;
}

/// `helm verify`: verifies a packaged chart against the `PATH.prov` file next to it. Failure is
/// the error; success returns the signer and the verified hash.
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(PathBuf, into))]
pub struct Verify {
    /// The packaged chart (`PATH`); `PATH.prov` must sit next to it.
    #[builder(start_fn)]
    pub path: PathBuf,
    /// Flag `--keyring`: the keyring that holds the public keys.
    pub keyring: Option<PathBuf>,
}

impl Verify {
    /// Verifies the archive at `path`.
    #[must_use]
    pub fn new(path: impl Into<PathBuf>) -> Self {
        Self::builder(path).build()
    }
}

impl Command for Verify {
    type Output = ChartVerification;
}