1use std::io::Write;23use anyhow::Result;4use clap::Clap;56use crate::host::Config;78#[derive(Clap)]9pub enum Secrets {10 11 ForceKeys,12 13 Add {14 15 machine: String,16 17 name: String,18 },19}2021impl Secrets {22 pub fn run(self, config: &Config) -> Result<()> {23 match self {24 Secrets::ForceKeys => {25 for host in config.list_hosts()? {26 if config.should_skip(&host) {27 continue;28 }29 config.key(&host)?;30 }31 }32 Secrets::Add { machine, name } => {33 let recipient = config.recipient(&machine)?;34 let encryptor = age::Encryptor::with_recipients(vec![Box::new(recipient)]);3536 let mut encrypted = vec![];37 {38 let mut w = encryptor.wrap_output(&mut encrypted)?;3940 let stdin = std::io::stdin();41 let mut lock = stdin.lock();42 std::io::copy(&mut lock, &mut w)?;43 w.flush()?;44 }4546 config.update_secret(&machine, &name, &encrypted)47 }48 }49 Ok(())50 }51}