git.delta.rocks / jrsonnet / refs/commits / fad91f8a3923

difftreelog

source

src/cmds/fetch_keys.rs881 Bsourcehistory
1use crate::host::FleetOpts;2use anyhow::Result;3use clap::Clap;4use log::{info, warn};56#[derive(Clap)]7pub struct FetchKeys {8	#[clap(flatten)]9	fleet_opts: FleetOpts,1011	/// If true - remove orphaned keys12	#[clap(long)]13	cleanup: bool,14}1516impl FetchKeys {17	pub fn run(self) -> Result<()> {18		let fleet = self.fleet_opts.build()?;19		let hosts = fleet.list_hosts()?;20		for host in hosts.iter() {21			if host.skip() {22				warn!("Skipped host {}", host.hostname);23				continue;24			}25			host.key()?;26		}27		let orphans: Vec<_> = fleet.list_orphaned_keys()?;28		if !orphans.is_empty() {29			if self.cleanup {30				info!("Removed orphan host keys:");31			} else {32				info!("Orphan host keys found, run with --cleanup to remove them from db:");33			}34			for (name, path) in orphans {35				info!("- {}", name);36				if self.cleanup {37					std::fs::remove_file(path)?;38				}39			}40		}41		Ok(())42	}43}