Skip to main content

helm_rs/command/
registry.rs

1use std::path::PathBuf;
2
3use crate::backend::Command;
4use crate::options::Secret;
5
6/// `helm registry login`: stores credentials for an OCI registry in the registry config.
7///
8/// The password or identity token reaches Helm through `--password-stdin` (never argv). Without a
9/// password Helm prompts on a terminal, which a backend run does not have, so it fails.
10#[derive(Debug, Clone, PartialEq, bon::Builder)]
11#[builder(
12    on(String, into),
13    on(PathBuf, into),
14    on(Secret, into),
15    on(bool, default)
16)]
17pub struct RegistryLogin {
18    /// The registry host (`host`).
19    #[builder(start_fn)]
20    pub host: String,
21    /// Flag `--username` (`-u`); empty with a password means an identity token.
22    pub username: Option<String>,
23    /// Flag `--password-stdin`: the password or identity token, written to Helm's stdin.
24    pub password: Option<Secret>,
25    /// Flag `--cert-file`: the SSL client certificate.
26    pub cert_file: Option<PathBuf>,
27    /// Flag `--key-file`: the SSL client key.
28    pub key_file: Option<PathBuf>,
29    /// Flag `--ca-file`: the CA bundle that verifies the server.
30    pub ca_file: Option<PathBuf>,
31    /// Flag `--insecure`: allow connections to a TLS registry without certificates.
32    pub insecure: bool,
33    /// Flag `--plain-http`: use insecure HTTP connections.
34    pub plain_http: bool,
35}
36
37impl RegistryLogin {
38    /// Logs in to `host` with Helm's defaults.
39    #[must_use]
40    pub fn new(host: impl Into<String>) -> Self {
41        Self::builder(host).build()
42    }
43}
44
45impl Command for RegistryLogin {
46    type Output = ();
47}
48
49/// `helm registry logout`: removes the stored credentials of a registry.
50#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
51#[builder(on(String, into))]
52pub struct RegistryLogout {
53    /// The registry host (`host`).
54    #[builder(start_fn)]
55    pub host: String,
56}
57
58impl RegistryLogout {
59    /// Logs out of `host`.
60    #[must_use]
61    pub fn new(host: impl Into<String>) -> Self {
62        Self::builder(host).build()
63    }
64}
65
66impl Command for RegistryLogout {
67    type Output = ();
68}