Fetch User Keys - simple tool for fetching SSH keys from various sources
1// SPDX-FileCopyrightText: 2024 Łukasz Niemier <#@hauleth.dev> 2// 3// SPDX-License-Identifier: EUPL-1.2 4 5use std::collections::HashMap; 6 7#[derive(PartialEq, Eq, Debug, Copy, Clone)] 8pub enum Format { 9 JSON, 10 JSONPretty, 11} 12 13impl Format { 14 pub fn render(self, output: &Output) -> String { 15 match self { 16 Format::JSON => serde_json::to_string(&output.keys).unwrap(), 17 Format::JSONPretty => serde_json::to_string_pretty(&output.keys).unwrap(), 18 } 19 } 20} 21 22impl std::fmt::Display for Format { 23 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 24 match *self { 25 Format::JSON => f.write_str("json"), 26 Format::JSONPretty => f.write_str("pretty"), 27 } 28 } 29} 30 31impl<'a> From<&'a str> for Format { 32 fn from(s: &'a str) -> Format { 33 match s { 34 "json" => Format::JSON, 35 "pretty" => Format::JSONPretty, 36 _ => unreachable!() 37 } 38 } 39} 40 41#[derive(Debug, serde::Serialize)] 42pub struct Output { 43 pub keys: HashMap<String, Vec<ssh_key::PublicKey>>, 44}