helm_rs/command/fetch.rs
1use std::path::PathBuf;
2
3use super::{ChartPathOptions, ChartRef};
4use crate::backend::Command;
5use crate::options::Secret;
6
7/// What Helm verified about a chart: the signer and the hash of the archive
8/// (`pkg/action/verify.go`, `pkg/action/pull.go`, Helm v4.3.0).
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ChartVerification {
11 /// The identities of the signing key (`Signed by:` lines), for example `Name <mail>`. Helm
12 /// iterates a Go map to print them, so the order is not defined.
13 pub signed_by: Vec<String>,
14 /// The fingerprint of the signing key, upper-case hex.
15 pub fingerprint: String,
16 /// The verified archive hash, for example `sha256:...`.
17 pub hash: String,
18}
19
20/// A chart or provenance blob in an OCI registry, as the `Pulled:`/`Pushed:` and `Digest:` line
21/// pairs of Helm's registry client name it (`pkg/registry/client.go`).
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct RegistryArtifact {
24 /// The reference without the `oci://` scheme, for example `host:5000/charts/web:1.2.3`.
25 pub reference: String,
26 /// The manifest digest, for example `sha256:...`.
27 pub digest: String,
28}
29
30/// What a successful `helm pull` printed (`pkg/action/pull.go`, Helm v4.3.0). Helm does not
31/// print where it saved the chart: that is `<destination>/<name>-<version>.tgz`, or with
32/// `untar` a directory below it.
33#[derive(Debug, Clone, Default, PartialEq, Eq)]
34pub struct Pulled {
35 /// The registry artifacts pulled, in order: the chart, then its provenance file when
36 /// `--verify` or `--prov` fetched one. Empty for a chart repository or a URL.
37 pub artifacts: Vec<RegistryArtifact>,
38 /// The verification report, present only with `--verify`.
39 pub verification: Option<ChartVerification>,
40 /// The `WARNING:` lines, for example a missing provenance file with `--prov`.
41 pub warnings: Vec<String>,
42}
43
44/// `helm pull`: downloads a chart from a repository, a URL or an OCI registry, and optionally
45/// unpacks it. The destination directory must exist. Helm's several-charts form is a loop over
46/// the charts with the same flags (`pkg/cmd/pull.go`), so this command pulls one chart; run it once
47/// per chart.
48#[derive(Debug, Clone, PartialEq, bon::Builder)]
49#[builder(on(PathBuf, into), on(bool, default))]
50pub struct Pull {
51 /// The chart to download (`[chart URL | repo/chartname]`).
52 #[builder(start_fn)]
53 pub chart: ChartRef,
54 /// The chart download flags, including `--verify` and `--keyring`.
55 #[builder(default)]
56 pub chart_path: ChartPathOptions,
57 /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored when a
58 /// version is set.
59 pub devel: bool,
60 /// Flag `--untar`: unpack the chart after downloading it.
61 pub untar: bool,
62 /// Flag `--untardir`: with `untar`, the directory the chart is expanded into (Helm's default
63 /// is `.`); a relative path is joined to `destination`.
64 pub untardir: Option<PathBuf>,
65 /// Flag `--destination` (`-d`): where to write the chart (Helm's default is `.`).
66 pub destination: Option<PathBuf>,
67 /// Flag `--prov`: fetch the provenance file without verifying it.
68 pub prov: bool,
69}
70
71impl Pull {
72 /// Pulls `chart` with Helm's defaults.
73 #[must_use]
74 pub fn new(chart: ChartRef) -> Self {
75 Self::builder(chart).build()
76 }
77}
78
79impl Command for Pull {
80 type Output = Pulled;
81}
82
83/// `helm push`: uploads a packaged chart (and its `.prov` file when it sits next to it) to an
84/// OCI registry. Helm 4.3 has only the OCI pusher.
85///
86/// The `password` never reaches argv: the CLI backend writes it, with the username, to a `0600`
87/// temporary registry config for the registry host of `remote`, like
88/// [`ChartPathOptions::password`].
89#[derive(Debug, Clone, PartialEq, bon::Builder)]
90#[builder(
91 on(String, into),
92 on(PathBuf, into),
93 on(Secret, into),
94 on(bool, default)
95)]
96pub struct Push {
97 /// The packaged chart (`[chart]`), a `.tgz` file.
98 #[builder(start_fn)]
99 pub chart: PathBuf,
100 /// The registry to push to (`[remote]`), `oci://host/path`; Helm appends the chart name and
101 /// version.
102 #[builder(start_fn)]
103 pub remote: String,
104 /// Flag `--cert-file`: the registry client SSL certificate.
105 pub cert_file: Option<PathBuf>,
106 /// Flag `--key-file`: the registry client SSL key.
107 pub key_file: Option<PathBuf>,
108 /// Flag `--ca-file`: the CA bundle that verifies HTTPS servers.
109 pub ca_file: Option<PathBuf>,
110 /// Flag `--insecure-skip-tls-verify`.
111 pub insecure_skip_tls_verify: bool,
112 /// Flag `--plain-http`: use insecure HTTP connections.
113 pub plain_http: bool,
114 /// Flag `--username`.
115 pub username: Option<String>,
116 /// Never a flag: see the type documentation.
117 pub password: Option<Secret>,
118}
119
120impl Push {
121 /// Pushes `chart` to `remote` with Helm's defaults.
122 #[must_use]
123 pub fn new(chart: impl Into<PathBuf>, remote: impl Into<String>) -> Self {
124 Self::builder(chart, remote).build()
125 }
126}
127
128impl Command for Push {
129 type Output = RegistryArtifact;
130}
131
132/// `helm verify`: verifies a packaged chart against the `PATH.prov` file next to it. Failure is
133/// the error; success returns the signer and the verified hash.
134#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
135#[builder(on(PathBuf, into))]
136pub struct Verify {
137 /// The packaged chart (`PATH`); `PATH.prov` must sit next to it.
138 #[builder(start_fn)]
139 pub path: PathBuf,
140 /// Flag `--keyring`: the keyring that holds the public keys.
141 pub keyring: Option<PathBuf>,
142}
143
144impl Verify {
145 /// Verifies the archive at `path`.
146 #[must_use]
147 pub fn new(path: impl Into<PathBuf>) -> Self {
148 Self::builder(path).build()
149 }
150}
151
152impl Command for Verify {
153 type Output = ChartVerification;
154}