helm_rs/command/chart_ref.rs
1//! How a command locates a chart: the chart reference and Helm's chart path flags.
2
3use std::ffi::OsStr;
4use std::path::PathBuf;
5
6use crate::options::Secret;
7
8/// A chart as `helm install`, `helm upgrade` and the other chart commands accept it
9/// (`ChartPathOptions.LocateChart`, `pkg/action/install.go`). Helm tries a local path first, then
10/// the remote forms.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum ChartRef {
13 /// A chart directory or a packaged `.tgz` on disk.
14 Path(PathBuf),
15 /// `repo/chart` for a repository in the repository config, or the bare chart name when
16 /// [`ChartPathOptions::repo`] gives the repository URL.
17 Repo(String),
18 /// An `oci://host/path/chart` reference.
19 Oci(String),
20 /// The absolute URL of a packaged chart.
21 Url(String),
22}
23
24impl ChartRef {
25 /// The positional argument Helm receives.
26 #[must_use]
27 pub fn as_os_str(&self) -> &OsStr {
28 match self {
29 Self::Path(path) => path.as_os_str(),
30 Self::Repo(text) | Self::Oci(text) | Self::Url(text) => OsStr::new(text),
31 }
32 }
33}
34
35/// The chart download flags shared by install, upgrade and the other commands that fetch a chart
36/// (`addChartPathOptionsFlags`, `pkg/cmd/flags.go`).
37///
38/// The `password` never reaches argv. For an `oci://` chart the CLI backend writes it to a `0600`
39/// temporary registry config (and passes the username through it too); for any other chart it
40/// refuses the command, because Helm 4.3 reads a repository password only from `--password` or a
41/// repository config entry (add the repository with a password first, then use
42/// [`ChartRef::Repo`]).
43#[derive(Debug, Clone, Default, PartialEq, bon::Builder)]
44#[builder(
45 on(String, into),
46 on(PathBuf, into),
47 on(Secret, into),
48 on(bool, default)
49)]
50#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
51pub struct ChartPathOptions {
52 /// Flag `--version`: a version or a constraint such as `^2.0.0`.
53 pub version: Option<String>,
54 /// Flag `--verify`: the chart must have a valid provenance file.
55 pub verify: bool,
56 /// Flag `--keyring`: the public keyring used by `--verify`.
57 pub keyring: Option<PathBuf>,
58 /// Flag `--repo`: the repository URL to look the chart up in.
59 pub repo: Option<String>,
60 /// Flag `--username`.
61 pub username: Option<String>,
62 /// Never a flag: see the type documentation.
63 pub password: Option<Secret>,
64 /// Flag `--cert-file`: the TLS client certificate.
65 pub cert_file: Option<PathBuf>,
66 /// Flag `--key-file`: the TLS client key.
67 pub key_file: Option<PathBuf>,
68 /// Flag `--ca-file`: the CA bundle that verifies HTTPS servers.
69 pub ca_file: Option<PathBuf>,
70 /// Flag `--insecure-skip-tls-verify`.
71 pub insecure_skip_tls_verify: bool,
72 /// Flag `--plain-http`: use HTTP instead of HTTPS.
73 pub plain_http: bool,
74 /// Flag `--pass-credentials`: send credentials to every domain, not only the repository's.
75 pub pass_credentials: bool,
76}