diff --git a/src/helm_client.rs b/src/helm_client.rs index f1fe84b..24e973d 100644 --- a/src/helm_client.rs +++ b/src/helm_client.rs @@ -7,6 +7,7 @@ use super::UninstallArg; use super::HelmError; use super::Chart; use super::InstalledChart; +use super::RepoAddArg; /// Client to manage helm operations #[derive(Debug)] @@ -75,6 +76,12 @@ impl HelmClient { Ok(()) } + pub fn repo_add_with_optionals(&self, optionals: RepoAddArg) -> Result<(), HelmError> { + let mut command: Command = optionals.into(); + command.result()?; + Ok(()) + } + /// Updates the local helm repository #[instrument(skip(self))] pub fn repo_update(&self) -> Result<(), HelmError> { diff --git a/src/lib.rs b/src/lib.rs index ef96d7f..08cc1fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ mod uninstall_arg; mod helm_client; mod chart; mod installed_chart; +mod repo_add_optionals; pub use crate::error::HelmError; @@ -12,6 +13,7 @@ pub use uninstall_arg::UninstallArg; pub use chart::Chart; pub use installed_chart::InstalledChart; pub use helm_client::HelmClient; +pub use repo_add_optionals::RepoAddArg; #[cfg(test)] diff --git a/src/repo_add_optionals.rs b/src/repo_add_optionals.rs new file mode 100644 index 0000000..b0799cb --- /dev/null +++ b/src/repo_add_optionals.rs @@ -0,0 +1,116 @@ +use std::process::Command; + +#[derive(Debug, Default)] +pub struct RepoAddArg { + chart: String, + location: String, + + force_update: Option, + insecure_skip_tls_verify: Option, + no_update: Option, + + ca_file: Option, + cert_file: Option, + key_file: Option, + password: Option, + username: Option +} + +impl RepoAddArg { + pub fn new(chart: &str, location: &str) -> RepoAddArg { + RepoAddArg{ + chart: chart.into(), + location: location.into(), + ..RepoAddArg::default() + } + } + + pub fn set_force_update>(mut self, value: S) -> Self { + self.force_update = Some(value.into()); + self + } + + pub fn set_insecure_skip_tls_verify>(mut self, value: S) -> Self { + self.insecure_skip_tls_verify = Some(value.into()); + self + } + + pub fn set_no_update>(mut self, value: S) -> Self { + self.no_update = Some(value.into()); + self + } + + pub fn set_ca_file>(mut self, value: S) -> Self { + self.ca_file = Some(value.into()); + self + } + + pub fn set_cert_file>(mut self, value: S) -> Self { + self.cert_file = Some(value.into()); + self + } + + pub fn set_key_file>(mut self, value: S) -> Self { + self.key_file = Some(value.into()); + self + } + + pub fn set_password>(mut self, value: S) -> Self { + self.password = Some(value.into()); + self + } + + pub fn set_username>(mut self, value: S) -> Self { + self.username = Some(value.into()); + self + } +} + +impl Into for RepoAddArg { + + fn into(self) -> Command { + let mut command = Command::new("helm"); + + command.args(&["repo", "add", self.chart.as_str(), self.location.as_str()]); + + if let Some(force_update) = &self.force_update { + if *force_update == true { + command.args(&["--force-update"]); + } + } + + if let Some(insecure_skip_tls_verify) = &self.insecure_skip_tls_verify { + if *insecure_skip_tls_verify == true { + command.args(&["--insecure-skip-tls-verify"]); + } + } + + if let Some(no_update) = &self.no_update { + if *no_update == true { + command.args(&["--no-update"]); + } + } + + if let Some(ca_file) = &self.ca_file { + command.args(&["--ca-file", ca_file.as_str()]); + } + + if let Some(cert_file) = &self.cert_file { + command.args(&["--cert-file", cert_file.as_str()]); + } + + if let Some(key_file) = &self.key_file { + command.args(&["--key-file", key_file.as_str()]); + } + + if let Some(password) = &self.password { + command.args(&["--password", password.as_str()]); + } + + if let Some(username) = &self.username { + command.args(&["--username", username.as_str()]); + } + command + } + +} \ No newline at end of file