added: paralell fetch
This commit is contained in:
12
src/certs.rs
12
src/certs.rs
@@ -1,8 +1,8 @@
|
||||
use anyhow::Context;
|
||||
use ssh_key::{Certificate, PublicKey};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{path::{Path, PathBuf}, fmt::Debug};
|
||||
use tokio::fs;
|
||||
use tracing::trace;
|
||||
use tracing::{trace, instrument};
|
||||
|
||||
pub async fn read_certs(
|
||||
ca: &PublicKey,
|
||||
@@ -11,7 +11,8 @@ pub async fn read_certs(
|
||||
read_dir(path.as_ref().join(ca_dir(ca))).await
|
||||
}
|
||||
|
||||
pub async fn read_dir(path: impl AsRef<Path>) -> anyhow::Result<Vec<Certificate>> {
|
||||
#[instrument]
|
||||
pub async fn read_dir(path: impl AsRef<Path> + Debug) -> anyhow::Result<Vec<Certificate>> {
|
||||
let mut dir = fs::read_dir(path.as_ref())
|
||||
.await
|
||||
.context("read certs dir")?;
|
||||
@@ -58,13 +59,15 @@ fn ca_dir(ca: &PublicKey) -> String {
|
||||
ca.comment().to_string()
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
fn cert_path(ca: &PublicKey, identifier: &str) -> String {
|
||||
let _ca_fingerprint = ca.fingerprint(Default::default());
|
||||
format!("{}/{}-cert.pub", ca_dir(ca), identifier)
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn store_cert(
|
||||
cert_dir: impl AsRef<Path>,
|
||||
cert_dir: impl AsRef<Path> + Debug,
|
||||
ca: &PublicKey,
|
||||
cert: &Certificate,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
@@ -84,6 +87,7 @@ pub async fn load_cert(
|
||||
) -> anyhow::Result<Option<Certificate>> {
|
||||
let path = cert_dir.as_ref().join(cert_path(ca, identifier));
|
||||
if !path.exists() {
|
||||
trace!("no certificate at {:?}", path);
|
||||
return Ok(None);
|
||||
}
|
||||
let contents = fs::read(&path)
|
||||
|
Reference in New Issue
Block a user