use std::sync::Arc;
use crate::engine::SecretsEngine;
pub struct EngineMount {
pub prefix: String,
pub engine: Arc<dyn SecretsEngine>,
}
#[derive(Default)]
pub struct Router {
mounts: Vec<EngineMount>,
}
impl Router {
pub fn new(mounts: Vec<EngineMount>) -> Self {
Self { mounts }
}
pub fn resolve<'a>(&self, path: &'a str) -> Option<(&EngineMount, &'a str)> {
self.mounts
.iter()
.filter(|m| path.starts_with(&m.prefix))
.max_by_key(|m| m.prefix.len())
.map(move |m| (m, path.strip_prefix(&m.prefix).unwrap_or("")))
}
}