Fetch User Keys - simple tool for fetching SSH keys from various sources
1use crate::output::Output; 2use crate::sources::*; 3 4use futures::prelude::*; 5 6#[derive(Debug, serde::Deserialize)] 7pub struct Entry { 8 pub name: String, 9 pub keys: Vec<Box<Source>>, 10} 11 12impl Entry { 13 pub async fn fetch(&self) -> (String, Vec<ssh_key::PublicKey>) { 14 let mut stream: Vec<_> = stream::iter(&self.keys) 15 .then(|k| async { k.fetch().await }) 16 .map(stream::iter) 17 .flatten() 18 .collect() 19 .await; 20 21 // Deduplicate keys, no need for duplicated entries 22 stream.sort(); 23 stream.dedup_by(|a, b| { 24 a.key_data() == b.key_data() 25 }); 26 27 (self.name.clone(), stream) 28 } 29} 30 31#[derive(Debug, serde::Deserialize)] 32pub struct Config { 33 #[serde(rename = "entry")] 34 pub entries: Vec<Entry>, 35} 36 37impl Config { 38 pub async fn fetch(&self) -> Result<Output, ()> { 39 let keys = stream::iter(&self.entries) 40 .then(Entry::fetch) 41 .collect() 42 .await; 43 44 Ok(Output { keys }) 45 } 46}