vault: Router can check for matching mounts

This commit is contained in:
Armon Dadgar 2015-03-11 17:56:01 -07:00
parent 88ed41abc2
commit 59052069bc
2 changed files with 19 additions and 0 deletions

View File

@ -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

View File

@ -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",
}