helm-rs 0.1.2

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
//! How a command locates a chart: the chart reference and Helm's chart path flags.

use std::ffi::OsStr;
use std::path::PathBuf;

use crate::options::Secret;

/// A chart as `helm install`, `helm upgrade` and the other chart commands accept it
/// (`ChartPathOptions.LocateChart`, `pkg/action/install.go`). Helm tries a local path first, then
/// the remote forms.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChartRef {
    /// A chart directory or a packaged `.tgz` on disk.
    Path(PathBuf),
    /// `repo/chart` for a repository in the repository config, or the bare chart name when
    /// [`ChartPathOptions::repo`] gives the repository URL.
    Repo(String),
    /// An `oci://host/path/chart` reference.
    Oci(String),
    /// The absolute URL of a packaged chart.
    Url(String),
}

impl ChartRef {
    /// The positional argument Helm receives.
    #[must_use]
    pub fn as_os_str(&self) -> &OsStr {
        match self {
            Self::Path(path) => path.as_os_str(),
            Self::Repo(text) | Self::Oci(text) | Self::Url(text) => OsStr::new(text),
        }
    }
}

/// The chart download flags shared by install, upgrade and the other commands that fetch a chart
/// (`addChartPathOptionsFlags`, `pkg/cmd/flags.go`).
///
/// The `password` never reaches argv. For an `oci://` chart the CLI backend writes it to a `0600`
/// temporary registry config (and passes the username through it too); for any other chart it
/// refuses the command, because Helm 4.3 reads a repository password only from `--password` or a
/// repository config entry (add the repository with a password first, then use
/// [`ChartRef::Repo`]).
#[derive(Debug, Clone, Default, PartialEq, bon::Builder)]
#[builder(
    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 ChartPathOptions {
    /// Flag `--version`: a version or a constraint such as `^2.0.0`.
    pub version: Option<String>,
    /// Flag `--verify`: the chart must have a valid provenance file.
    pub verify: bool,
    /// Flag `--keyring`: the public keyring used by `--verify`.
    pub keyring: Option<PathBuf>,
    /// Flag `--repo`: the repository URL to look the chart up in.
    pub repo: Option<String>,
    /// Flag `--username`.
    pub username: Option<String>,
    /// Never a flag: see the type documentation.
    pub password: Option<Secret>,
    /// Flag `--cert-file`: the TLS client certificate.
    pub cert_file: Option<PathBuf>,
    /// Flag `--key-file`: the TLS client 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 HTTP instead of HTTPS.
    pub plain_http: bool,
    /// Flag `--pass-credentials`: send credentials to every domain, not only the repository's.
    pub pass_credentials: bool,
}