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 mounts(&self) -> &[EngineMount] {
26 &self.mounts
27 }
28
29 pub fn resolve<'a>(&self, path: &'a str) -> Option<(&EngineMount, &'a str)> {
31 self.mounts
32 .iter()
33 .filter(|m| path.starts_with(&m.prefix))
34 .max_by_key(|m| m.prefix.len())
35 .map(move |m| (m, path.strip_prefix(&m.prefix).unwrap_or("")))
36 }
37}