vault: Router can check for matching mounts
This commit is contained in:
parent
88ed41abc2
commit
59052069bc
|
@ -91,6 +91,17 @@ func (r *Router) Remount(src, dst string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MatchingMOunt returns the mount prefix that would be used for a path
|
||||
func (r *Router) MatchingMount(path string) string {
|
||||
r.l.RLock()
|
||||
mount, _, ok := r.root.LongestPrefix(path)
|
||||
r.l.RUnlock()
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return mount
|
||||
}
|
||||
|
||||
// Route is used to route a given request
|
||||
func (r *Router) Route(req *Request) (*Response, error) {
|
||||
// Find the mount point
|
||||
|
|
|
@ -39,6 +39,14 @@ func TestRouter_Mount(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if path := r.MatchingMount("prod/aws/foo"); path != "prod/aws/" {
|
||||
t.Fatalf("bad: %s", path)
|
||||
}
|
||||
|
||||
if path := r.MatchingMount("stage/aws/foo"); path != "" {
|
||||
t.Fatalf("bad: %s", path)
|
||||
}
|
||||
|
||||
req := &Request{
|
||||
Path: "prod/aws/foo",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue