helm_rs/command/repo.rs
1use std::path::PathBuf;
2use std::time::Duration;
3
4use serde::Deserialize;
5
6use super::builder_collections;
7use crate::backend::Command;
8use crate::options::Secret;
9
10/// `helm repo add`: adds a chart repository to `repositories.yaml` and downloads its index.
11///
12/// The password reaches Helm through `--password-stdin` (never argv). Helm reads stdin only when a
13/// username is set, so a password without a username is rejected when the command is built.
14#[derive(Debug, Clone, PartialEq, bon::Builder)]
15#[builder(
16 on(String, into),
17 on(PathBuf, into),
18 on(Secret, into),
19 on(bool, default)
20)]
21#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
22pub struct RepoAdd {
23 /// The repository name (`NAME`); it must not contain `/`.
24 #[builder(start_fn)]
25 pub name: String,
26 /// The repository URL (`URL`).
27 #[builder(start_fn)]
28 pub url: String,
29 /// Flag `--username`: the chart repository username.
30 pub username: Option<String>,
31 /// Flag `--password-stdin`: the chart repository password, written to Helm's stdin and never
32 /// to argv. Helm stores it in plain text in `repositories.yaml` (`password:` next to the
33 /// repository), so that file is as sensitive as the password; Helm reads it from stdin only
34 /// when a username is also set.
35 pub password: Option<Secret>,
36 /// Flag `--pass-credentials`: pass credentials to all domains.
37 pub pass_credentials: bool,
38 /// Flag `--force-update`: replace the repository if it already exists.
39 pub force_update: bool,
40 /// Flag `--allow-deprecated-repos`: allow the permanently deleted official repositories.
41 pub allow_deprecated_repos: bool,
42 /// Flag `--timeout`: time to wait for the index download (Helm's default is 2m).
43 pub timeout: Option<Duration>,
44 /// Flag `--cert-file`: the SSL client certificate.
45 pub cert_file: Option<PathBuf>,
46 /// Flag `--key-file`: the SSL client key.
47 pub key_file: Option<PathBuf>,
48 /// Flag `--ca-file`: the CA bundle that verifies the server.
49 pub ca_file: Option<PathBuf>,
50 /// Flag `--insecure-skip-tls-verify`: skip the TLS certificate checks.
51 pub insecure_skip_tls_verify: bool,
52}
53
54impl RepoAdd {
55 /// Adds the repository `name` at `url` with Helm's defaults.
56 #[must_use]
57 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
58 Self::builder(name, url).build()
59 }
60}
61
62impl Command for RepoAdd {
63 type Output = ();
64}
65
66/// `helm repo index`: writes `index.yaml` for the packaged charts (`*.tgz`) in a directory. Read
67/// the result natively with [`Index::load`](crate::repo::Index::load).
68#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
69#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
70pub struct RepoIndex {
71 /// The directory of packaged charts (`DIR`); `index.yaml` is written inside it.
72 #[builder(start_fn)]
73 pub dir: PathBuf,
74 /// Flag `--url`: the absolute URL charts are served from.
75 pub url: Option<String>,
76 /// Flag `--merge`: merge the generated index into this index file (local charts win).
77 pub merge: Option<PathBuf>,
78 /// Flag `--json`: write the index as JSON instead of YAML.
79 pub json: bool,
80}
81
82impl RepoIndex {
83 /// Indexes the charts in `dir`.
84 #[must_use]
85 pub fn new(dir: impl Into<PathBuf>) -> Self {
86 Self::builder(dir).build()
87 }
88}
89
90impl Command for RepoIndex {
91 type Output = ();
92}
93
94/// `helm repo list`: the configured chart repositories, requested as `-o json`.
95#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
96pub struct RepoList;
97
98/// One configured repository (`repositoryElement` in `pkg/cmd/repo_list.go`, Helm v4.3.0).
99#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
100pub struct Repository {
101 /// The repository name.
102 pub name: String,
103 /// The repository URL.
104 pub url: String,
105}
106
107impl Command for RepoList {
108 type Output = Vec<Repository>;
109}
110
111/// `helm repo remove`: removes repositories and their cached indexes.
112#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
113#[builder(start_fn(name = start, vis = ""))]
114pub struct RepoRemove {
115 /// The repositories to remove (`REPO1 [REPO2 ...]`); at least one.
116 #[builder(field)]
117 pub names: Vec<String>,
118}
119
120builder_collections! {
121 RepoRemoveBuilder, repo_remove_builder;
122 vec names / name: String, "`REPO` arguments", "the names of the repositories";
123}
124
125impl RepoRemove {
126 /// Starts building for the repositories in `names`, the first of the required `REPO...`.
127 pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> RepoRemoveBuilder {
128 Self::start().names(names)
129 }
130
131 /// Removes the named repositories.
132 #[must_use]
133 pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
134 Self::builder(names).build()
135 }
136}
137
138impl Command for RepoRemove {
139 type Output = ();
140}
141
142/// `helm repo update`: downloads the indexes of the repositories.
143#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
144#[builder(on(String, into))]
145pub struct RepoUpdate {
146 /// The repositories to update (`[REPO1 [REPO2 ...]]`); empty updates all of them.
147 #[builder(field)]
148 pub names: Vec<String>,
149 /// Flag `--timeout`: time to wait for each index download (Helm's default is 2m).
150 pub timeout: Option<Duration>,
151}
152
153builder_collections! {
154 RepoUpdateBuilder, repo_update_builder;
155 vec names / name: String, "`REPO` arguments", "the names of the repositories";
156}
157
158impl Command for RepoUpdate {
159 type Output = ();
160}