Skip to content

Commit

Permalink
Create a function to allow adding repositories with optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Claudino committed May 26, 2021
1 parent d883e49 commit 0188647
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/helm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod uninstall_arg;
mod helm_client;
mod chart;
mod installed_chart;
mod repo_add_optionals;

pub use crate::error::HelmError;

Expand All @@ -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)]
Expand Down
116 changes: 116 additions & 0 deletions src/repo_add_optionals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use std::process::Command;

#[derive(Debug, Default)]
pub struct RepoAddArg {
chart: String,
location: String,

force_update: Option<bool>,
insecure_skip_tls_verify: Option<bool>,
no_update: Option<bool>,

ca_file: Option<String>,
cert_file: Option<String>,
key_file: Option<String>,
password: Option<String>,
username: Option<String>
}

impl RepoAddArg {
pub fn new(chart: &str, location: &str) -> RepoAddArg {
RepoAddArg{
chart: chart.into(),
location: location.into(),
..RepoAddArg::default()
}
}

pub fn set_force_update<S: Into<bool>>(mut self, value: S) -> Self {
self.force_update = Some(value.into());
self
}

pub fn set_insecure_skip_tls_verify<S: Into<bool>>(mut self, value: S) -> Self {
self.insecure_skip_tls_verify = Some(value.into());
self
}

pub fn set_no_update<S: Into<bool>>(mut self, value: S) -> Self {
self.no_update = Some(value.into());
self
}

pub fn set_ca_file<S: Into<String>>(mut self, value: S) -> Self {
self.ca_file = Some(value.into());
self
}

pub fn set_cert_file<S: Into<String>>(mut self, value: S) -> Self {
self.cert_file = Some(value.into());
self
}

pub fn set_key_file<S: Into<String>>(mut self, value: S) -> Self {
self.key_file = Some(value.into());
self
}

pub fn set_password<S: Into<String>>(mut self, value: S) -> Self {
self.password = Some(value.into());
self
}

pub fn set_username<S: Into<String>>(mut self, value: S) -> Self {
self.username = Some(value.into());
self
}
}

impl Into<Command> 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
}

}

0 comments on commit 0188647

Please sign in to comment.