helm-rs 0.1.2

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

use serde::Deserialize;

use super::builder_collections;
use crate::backend::Command;
use crate::options::Secret;

/// `helm repo add`: adds a chart repository to `repositories.yaml` and downloads its index.
///
/// The password reaches Helm through `--password-stdin` (never argv). Helm reads stdin only when a
/// username is set, so a password without a username is rejected when the command is built.
#[derive(Debug, Clone, 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 RepoAdd {
    /// The repository name (`NAME`); it must not contain `/`.
    #[builder(start_fn)]
    pub name: String,
    /// The repository URL (`URL`).
    #[builder(start_fn)]
    pub url: String,
    /// Flag `--username`: the chart repository username.
    pub username: Option<String>,
    /// Flag `--password-stdin`: the chart repository password, written to Helm's stdin and never
    /// to argv. Helm stores it in plain text in `repositories.yaml` (`password:` next to the
    /// repository), so that file is as sensitive as the password; Helm reads it from stdin only
    /// when a username is also set.
    pub password: Option<Secret>,
    /// Flag `--pass-credentials`: pass credentials to all domains.
    pub pass_credentials: bool,
    /// Flag `--force-update`: replace the repository if it already exists.
    pub force_update: bool,
    /// Flag `--allow-deprecated-repos`: allow the permanently deleted official repositories.
    pub allow_deprecated_repos: bool,
    /// Flag `--timeout`: time to wait for the index download (Helm's default is 2m).
    pub timeout: Option<Duration>,
    /// Flag `--cert-file`: the SSL client certificate.
    pub cert_file: Option<PathBuf>,
    /// Flag `--key-file`: the SSL client key.
    pub key_file: Option<PathBuf>,
    /// Flag `--ca-file`: the CA bundle that verifies the server.
    pub ca_file: Option<PathBuf>,
    /// Flag `--insecure-skip-tls-verify`: skip the TLS certificate checks.
    pub insecure_skip_tls_verify: bool,
}

impl RepoAdd {
    /// Adds the repository `name` at `url` with Helm's defaults.
    #[must_use]
    pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
        Self::builder(name, url).build()
    }
}

impl Command for RepoAdd {
    type Output = ();
}

/// `helm repo index`: writes `index.yaml` for the packaged charts (`*.tgz`) in a directory. Read
/// the result natively with [`Index::load`](crate::repo::Index::load).
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
pub struct RepoIndex {
    /// The directory of packaged charts (`DIR`); `index.yaml` is written inside it.
    #[builder(start_fn)]
    pub dir: PathBuf,
    /// Flag `--url`: the absolute URL charts are served from.
    pub url: Option<String>,
    /// Flag `--merge`: merge the generated index into this index file (local charts win).
    pub merge: Option<PathBuf>,
    /// Flag `--json`: write the index as JSON instead of YAML.
    pub json: bool,
}

impl RepoIndex {
    /// Indexes the charts in `dir`.
    #[must_use]
    pub fn new(dir: impl Into<PathBuf>) -> Self {
        Self::builder(dir).build()
    }
}

impl Command for RepoIndex {
    type Output = ();
}

/// `helm repo list`: the configured chart repositories, requested as `-o json`.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct RepoList;

/// One configured repository (`repositoryElement` in `pkg/cmd/repo_list.go`, Helm v4.3.0).
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct Repository {
    /// The repository name.
    pub name: String,
    /// The repository URL.
    pub url: String,
}

impl Command for RepoList {
    type Output = Vec<Repository>;
}

/// `helm repo remove`: removes repositories and their cached indexes.
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(start_fn(name = start, vis = ""))]
pub struct RepoRemove {
    /// The repositories to remove (`REPO1 [REPO2 ...]`); at least one.
    #[builder(field)]
    pub names: Vec<String>,
}

builder_collections! {
    RepoRemoveBuilder, repo_remove_builder;
    vec names / name: String, "`REPO` arguments", "the names of the repositories";
}

impl RepoRemove {
    /// Starts building for the repositories in `names`, the first of the required `REPO...`.
    pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> RepoRemoveBuilder {
        Self::start().names(names)
    }

    /// Removes the named repositories.
    #[must_use]
    pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
        Self::builder(names).build()
    }
}

impl Command for RepoRemove {
    type Output = ();
}

/// `helm repo update`: downloads the indexes of the repositories.
#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into))]
pub struct RepoUpdate {
    /// The repositories to update (`[REPO1 [REPO2 ...]]`); empty updates all of them.
    #[builder(field)]
    pub names: Vec<String>,
    /// Flag `--timeout`: time to wait for each index download (Helm's default is 2m).
    pub timeout: Option<Duration>,
}

builder_collections! {
    RepoUpdateBuilder, repo_update_builder;
    vec names / name: String, "`REPO` arguments", "the names of the repositories";
}

impl Command for RepoUpdate {
    type Output = ();
}