From b523e9fd9a0c93f95ac7d293e836672f72b809dc Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sun, 15 Jan 2023 21:00:53 +0100 Subject: [PATCH] Remove unused stuff --- src/connectors/argo.rs | 23 +++---- src/connectors/helmfile.rs | 2 +- src/main.rs | 124 ++----------------------------------- src/types/mod.rs | 2 +- 4 files changed, 18 insertions(+), 133 deletions(-) diff --git a/src/connectors/argo.rs b/src/connectors/argo.rs index d1a302e..ecd2ed0 100644 --- a/src/connectors/argo.rs +++ b/src/connectors/argo.rs @@ -1,10 +1,13 @@ -use clap::Arg; -use log::{debug, info, error}; -use serde_json::from_str; use crate::types::{self, HelmRepo}; +use log::{debug, error, info}; +use serde_json::from_str; use super::Connector; -use std::{borrow::Borrow, io::{Result, Error, ErrorKind}, process::Command}; +use std::{ + borrow::Borrow, + io::{Error, ErrorKind, Result}, + process::Command, +}; pub(crate) struct Argo; @@ -96,7 +99,7 @@ impl Connector for Argo { ); } } - + Ok(()) } else { Err(Error::new( @@ -104,12 +107,10 @@ impl Connector for Argo { String::from_utf8_lossy(&output.stderr), )) } - } - } -impl Argo{ -pub(crate) fn init() -> Argo { - Argo +impl Argo { + pub(crate) fn init() -> Argo { + Argo + } } -} \ No newline at end of file diff --git a/src/connectors/helmfile.rs b/src/connectors/helmfile.rs index fb8ff6e..bae5885 100644 --- a/src/connectors/helmfile.rs +++ b/src/connectors/helmfile.rs @@ -4,7 +4,7 @@ use serde_json::from_str; use crate::types; use super::Connector; -use std::{borrow::Borrow, fmt::format, io::Result, process::Command}; +use std::{borrow::Borrow, io::Result, process::Command}; pub(crate) struct Helmfile { path: String, diff --git a/src/main.rs b/src/main.rs index 49ee268..7fc20cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,14 +9,13 @@ use serde::{Deserialize, Serialize}; use serde_json::from_str; use std::{ borrow::Borrow, - fmt::{self, format}, - io::{Error, ErrorKind, Result}, + io::Result, process::{exit, Command}, }; use tabled::Tabled; use version_compare::{Cmp, Version}; -use crate::types::HelmChart; +use crate::types::{HelmChart, Status}; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] enum Kinds { @@ -58,23 +57,6 @@ struct LocalCharts { version: Option, } -/// Three possible statuses of versions comparison -#[derive(Clone, Serialize)] -enum Status { - Uptodate, - Outdated, - Missing, -} - -impl fmt::Display for Status { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Status::Uptodate => write!(f, "Up-to-date"), - Status::Outdated => write!(f, "Outdated"), - Status::Missing => write!(f, "Missing"), - } - } -} #[derive(Clone, Tabled, Serialize)] struct ExecResult { name: String, @@ -110,7 +92,7 @@ fn main() { if !args.no_sync { info!("syncing helm repositories"); - let res = match args.kind { + let res = match args.kind { Kinds::Argo => Argo::init().sync_repos(), Kinds::Helm => Helm::init().sync_repos(), Kinds::Helmfile => Helmfile::init(args.path).sync_repos(), @@ -122,7 +104,7 @@ fn main() { } charts.iter().for_each(|a| { - let err = check_chart(&mut result, a); + check_chart(&mut result, a).unwrap(); }); // Parse the helmfile @@ -269,104 +251,6 @@ fn handle_result(result: &Vec, outdated_fail: bool) -> Result Ok(failed) } -/// Downloading repos from repositories -fn repo_sync() -> Result<()> { - info!("syncing helm repos"); - let cmd: String = "argocd app list -o json | jq '[ .[] | {name: .spec.source.chart, url: .spec.source.repoURL} ]'".to_string(); - let output = Command::new("bash") - .arg("-c") - .arg(cmd) - .output() - .expect("helmfile is failed"); - info!("{:?}", output.clone()); - if output.status.success() { - let repos: Vec = serde_json::from_slice(&output.stdout).unwrap(); - info!("adding repositories"); - for repo in repos.iter() { - let name = repo.name.clone(); - if name.is_some() { - info!( - "syncing {} with the origin {}", - name.clone().unwrap(), - repo.url - ); - let cmd = format!( - "helm repo add {} {}", - name.clone().unwrap(), - repo.url.clone() - ); - debug!("running {}", cmd); - let output = Command::new("bash") - .arg("-c") - .arg(cmd) - .output() - .expect("helm repo sync is failed"); - match output.status.success() { - true => { - info!( - "{} with the origin {} is synced successfully", - name.unwrap(), - repo.url - ); - } - false => { - error!( - "{} with the origin {} can't be synced", - name.unwrap(), - repo.url - ) - } - } - } - } - let cmd = "helm repo update"; - let output = Command::new("bash") - .arg("-c") - .arg(cmd) - .output() - .expect("helm repo sync is failed"); - match output.status.success() { - true => { - info!("repositories are updated successfully"); - } - false => { - error!( - "repositories can't be updated, {}", - String::from_utf8_lossy(&output.stderr) - ); - } - } - - Ok(()) - } else { - Err(Error::new( - ErrorKind::Other, - String::from_utf8_lossy(&output.stderr), - )) - } -} - -/// Run helmfile list and write the result into struct -fn parse_argo_apps() -> Result> { - let cmd: String = "argocd app list -o json | jq '[.[] | {chart: .spec.source.chart, version: .spec.source.targetRevision}]'".to_string(); - - debug!("executing '${}'", cmd); - let output = Command::new("bash") - .arg("-c") - .arg(cmd) - .output() - .expect("helmfile is failed"); - let helm_stdout = String::from_utf8_lossy(&output.stdout); - - match from_str::>(Borrow::borrow(&helm_stdout)) { - Ok(mut charts) => { - charts.dedup(); - Ok(charts) - } - Err(err) => Err(err.into()), - } -} - /// Takes two version and returns the newer one. fn get_newer_version(v1: String, v2: String) -> String { match Version::from(&v1.replace('v', "")) diff --git a/src/types/mod.rs b/src/types/mod.rs index a0be023..768c0de 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -16,7 +16,7 @@ pub(crate) struct HelmRepo { } #[derive(Clone, Serialize)] -enum Status { +pub(crate) enum Status { Uptodate, Outdated, Missing,