1use std::sync::Arc;
2
3use crate::engine::SecretsEngine;
4
5pub struct EngineMount {
6 pub prefix: String,
7 pub engine: Arc<dyn SecretsEngine>,
8}
9
10#[derive(Default)]
14pub struct Router {
15 mounts: Vec<EngineMount>,
16}
17
18impl Router {
19 pub fn new(mounts: Vec<EngineMount>) -> Self {
20 Self { mounts }
21 }
22
23 pub fn resolve<'a>(&self, path: &'a str) -> Option<(&EngineMount, &'a str)> {
25 self.mounts
26 .iter()
27 .filter(|m| path.starts_with(&m.prefix))
28 .max_by_key(|m| m.prefix.len())
29 .map(move |m| (m, path.strip_prefix(&m.prefix).unwrap_or("")))
30 }
31}