open-vault/vault/dynamic_system_view.go
Jeff Mitchell ace611d56d Address items from feedback. Make MountConfig use values rather than
pointers and change how config is read to compensate.
2015-09-10 15:09:54 -04:00

55 lines
1 KiB
Go

package vault
import (
"fmt"
"strings"
"time"
)
type dynamicSystemView struct {
core *Core
path string
}
func (d dynamicSystemView) DefaultLeaseTTL() (time.Duration, error) {
def, _, err := d.fetchTTLs()
if err != nil {
return 0, err
}
return def, nil
}
func (d dynamicSystemView) MaxLeaseTTL() (time.Duration, error) {
_, max, err := d.fetchTTLs()
if err != nil {
return 0, err
}
return max, nil
}
// TTLsByPath returns the default and max TTLs corresponding to a particular
// mount point, or the system default
func (d dynamicSystemView) fetchTTLs() (def, max time.Duration, retErr error) {
// Ensure we end the path in a slash
if !strings.HasSuffix(d.path, "/") {
d.path += "/"
}
me := d.core.router.MatchingMountEntry(d.path)
if me == nil {
return 0, 0, fmt.Errorf("[ERR] core: failed to get mount entry for %s", d.path)
}
def = d.core.defaultLeaseTTL
max = d.core.maxLeaseTTL
if me.Config.DefaultLeaseTTL != 0 {
def = me.Config.DefaultLeaseTTL
}
if me.Config.MaxLeaseTTL != 0 {
max = me.Config.MaxLeaseTTL
}
return
}