Fetch User Keys - simple tool for fetching SSH keys from various sources

style: reformat codebase

hauleth.dev 85a5a819 f76bdfd3

verified
Changed files
+49 -62
cli
xtask
src
+3 -12
cli/src/config.rs
···
impl Entry {
pub fn fetch(&self) -> (String, Vec<ssh_key::PublicKey>) {
-
let mut stream: Vec<_> = self.keys
-
.par_iter()
-
.map(|k| k.fetch())
-
.flatten()
-
.collect();
+
let mut stream: Vec<_> = self.keys.par_iter().map(|k| k.fetch()).flatten().collect();
// Deduplicate keys, no need for duplicated entries
stream.sort();
-
stream.dedup_by(|a, b| {
-
a.key_data() == b.key_data()
-
});
+
stream.dedup_by(|a, b| a.key_data() == b.key_data());
(self.name.clone(), stream)
}
···
impl Config {
pub fn fetch(&self) -> Result<Output, ()> {
-
let keys = self.entries
-
.par_iter()
-
.map(Entry::fetch)
-
.collect();
+
let keys = self.entries.par_iter().map(Entry::fetch).collect();
Ok(Output { keys })
}
+2 -2
cli/src/main.rs
···
//
// SPDX-License-Identifier: EUPL-1.2
-
use simple_eyre::eyre::Result;
use clap::Parser;
-
use std::path::Path;
+
use simple_eyre::eyre::Result;
use std::fs::File;
use std::io::{self, prelude::*};
+
use std::path::Path;
#[derive(Debug, Clone)]
enum Input {
+1 -1
cli/src/output/mod.rs
···
"json-pretty" => Format::JSONPretty,
"toml" => Format::TOML,
"toml-pretty" => Format::TOMLPretty,
-
_ => unreachable!()
+
_ => unreachable!(),
}
}
}
+6 -1
cli/src/sources/atproto.rs
···
url.set_path("xrpc/com.atproto.repo.listRecords");
-
let data = ureq::get(&url.to_string()).call().unwrap().body_mut().read_to_string().unwrap();
+
let data = ureq::get(&url.to_string())
+
.call()
+
.unwrap()
+
.body_mut()
+
.read_to_string()
+
.unwrap();
let decoded: resp::Resp = serde_json::from_str(&data).unwrap();
+1 -1
cli/src/sources/helpers.rs
···
//
// SPDX-License-Identifier: EUPL-1.2
-
use std::str::FromStr;
use std::fmt;
+
use std::str::FromStr;
use serde::{de, Deserialize, Deserializer};
+16 -33
cli/src/sources/mod.rs
···
Source::Raw(ref raw) => raw.fetch(),
Source::Hosts(ref raw) => raw.fetch(),
Source::Http(ref raw) => raw.fetch(),
-
Source::Github(ref user) => {
-
Http {
-
url: format!("https://github.com/{user}.keys"),
-
}
-
.fetch()
+
Source::Github(ref user) => Http {
+
url: format!("https://github.com/{user}.keys"),
}
-
Source::Sourcehut(ref user) => {
-
Http {
-
url: format!("https://meta.sr.ht/{user}.keys"),
-
}
-
.fetch()
+
.fetch(),
+
Source::Sourcehut(ref user) => Http {
+
url: format!("https://meta.sr.ht/{user}.keys"),
}
-
Source::Gitlab(ref user) => {
-
Http {
-
url: format!("https://gitlab.com/{user}.keys"),
-
}
-
.fetch()
+
.fetch(),
+
Source::Gitlab(ref user) => Http {
+
url: format!("https://gitlab.com/{user}.keys"),
}
-
Source::Codeberg(ref user) => {
-
Http {
-
url: format!("https://codeberg.org/{user}.keys"),
-
}
-
.fetch()
+
.fetch(),
+
Source::Codeberg(ref user) => Http {
+
url: format!("https://codeberg.org/{user}.keys"),
}
+
.fetch(),
Source::Tangled(ref atproto) => atproto.fetch(),
}
}
···
impl Fetch for Hosts {
fn fetch(&self) -> Vec<PublicKey> {
// TODO: Check if we can do it in-process instead of shelling out to `ssh-keyscan`
-
let result = Command::new("ssh-keyscan")
-
.args(&self.0)
-
.output()
-
.unwrap();
+
let result = Command::new("ssh-keyscan").args(&self.0).output().unwrap();
std::str::from_utf8(&result.stdout)
.unwrap()
···
.map(str::trim)
// Remove comments
.filter(|line| !line.starts_with("#"))
-
.map(|line| {
-
// Ignore first column as it contain hostname which is not
-
// needed there
-
line.split(' ')
-
.skip(1)
-
.collect::<Box<[_]>>()
-
.join(" ")
-
.to_owned()
-
})
+
// Ignore first column as it contain hostname which is not
+
// needed there
+
.map(|line| line.split_once(' ').unwrap().1)
.map(|k| PublicKey::from_openssh(&k).unwrap())
.collect()
}
+13 -9
flake.lock
···
"nixpkgs": "nixpkgs_3"
},
"locked": {
-
"lastModified": 1744588088,
-
"narHash": "sha256-jymEVhRPzvzVP8XrXJcnVFUmle/FKLZIfSq+9EiobQE=",
+
"lastModified": 1744815543,
+
"narHash": "sha256-ybqhaIuv8OU0f14Rr+1ilxE4iTCnguXi/60g4ys6JOI=",
"owner": "cachix",
"repo": "devenv",
-
"rev": "1e6c06a058dae3791c0303eb99636cee9605c8d9",
+
"rev": "2e0e691414835585eeddd1e4e740b45b362052cc",
"type": "github"
},
"original": {
···
},
"nixpkgs_4": {
"locked": {
-
"lastModified": 0,
-
"narHash": "sha256-bWSjxDwq7iVePrhmA7tY2dyMWHuNJo8knkO4y+q4ZkY=",
-
"path": "/nix/store/5r0zii3rap2dyfyip31pdf9f0hpvv3d7-source",
-
"type": "path"
+
"lastModified": 1744536153,
+
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
+
"owner": "NixOS",
+
"repo": "nixpkgs",
+
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
+
"type": "github"
},
"original": {
-
"id": "nixpkgs",
-
"type": "indirect"
+
"owner": "NixOS",
+
"ref": "nixpkgs-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
}
},
"root": {
+4 -2
flake.nix
···
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
-
nixpkgs.url = "flake:nixpkgs";
+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
devenv.url = "github:cachix/devenv";
};
···
};
devenv.shells.default = {
-
languages.rust.enable = true;
+
languages.rust = {
+
enable = true;
+
};
packages =
[
+3 -1
xtask/src/main.rs
···
let entry = entry?;
let file_name = entry.file_name();
let file_name = Path::new(&file_name);
-
if file_name.extension() != Some(std::ffi::OsStr::new("scd")) { continue }
+
if file_name.extension() != Some(std::ffi::OsStr::new("scd")) {
+
continue;
+
}
let outname = Path::file_stem(file_name).unwrap();
let page = Path::new(outname).extension().unwrap().to_str().unwrap();