vault: Added MatchingView method

This commit is contained in:
Armon Dadgar 2015-04-02 11:03:59 -07:00
parent d5e5499ddd
commit c718408055
2 changed files with 20 additions and 1 deletions

View File

@ -83,7 +83,7 @@ func (r *Router) Remount(src, dst string) error {
return nil
}
// MatchingMOunt returns the mount prefix that would be used for a path
// 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)
@ -94,6 +94,17 @@ func (r *Router) MatchingMount(path string) string {
return mount
}
// MatchingView returns the view used for a path
func (r *Router) MatchingView(path string) *BarrierView {
r.l.RLock()
_, raw, ok := r.root.LongestPrefix(path)
r.l.RUnlock()
if !ok {
return nil
}
return raw.(*mountEntry).view
}
// Route is used to route a given request
func (r *Router) Route(req *logical.Request) (*logical.Response, error) {
// Find the mount point

View File

@ -54,10 +54,18 @@ func TestRouter_Mount(t *testing.T) {
t.Fatalf("bad: %s", path)
}
if v := r.MatchingView("prod/aws/foo"); v != view {
t.Fatalf("bad: %s", v)
}
if path := r.MatchingMount("stage/aws/foo"); path != "" {
t.Fatalf("bad: %s", path)
}
if v := r.MatchingView("stage/aws/foo"); v != nil {
t.Fatalf("bad: %s", v)
}
req := &logical.Request{
Path: "prod/aws/foo",
}