From b74fa8c888577f9ff92a94d11f923b3e7467dfa1 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 27 Aug 2015 11:25:07 -0700 Subject: [PATCH] Make DefaultSystemView StaticSystemView with statically-configured information. Export this from Framework to make it easy to override for testing. --- logical/framework/backend.go | 20 ++++++++------------ logical/system_config.go | 14 +++++++------- vault/core.go | 8 -------- vault/mount.go | 6 +++--- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/logical/framework/backend.go b/logical/framework/backend.go index 37c680655..4ebda31b9 100644 --- a/logical/framework/backend.go +++ b/logical/framework/backend.go @@ -56,10 +56,13 @@ type Backend struct { // See the built-in AuthRenew helpers in lease.go for common callbacks. AuthRenew OperationFunc - logger *log.Logger - once sync.Once - pathsRe []*regexp.Regexp - sysconfig logical.SystemView + // System provides an interface to access certain system configuration + // information, such as globally configured default and max lease TTLs. + System logical.SystemView + + logger *log.Logger + once sync.Once + pathsRe []*regexp.Regexp } // OperationFunc is the callback called for an operation on a path. @@ -143,7 +146,7 @@ func (b *Backend) SpecialPaths() *logical.Paths { // Setup is used to initialize the backend with the initial backend configuration func (b *Backend) Setup(config *logical.BackendConfig) (logical.Backend, error) { b.logger = config.Logger - b.sysconfig = config.System + b.System = config.System return b, nil } @@ -157,13 +160,6 @@ func (b *Backend) Logger() *log.Logger { return log.New(ioutil.Discard, "", 0) } -// SystemConfig can be used to get an object that provides methods for -// looking up some system configuration information, such as the global -// max lease. -func (b *Backend) SystemConfig() logical.SystemView { - return b.sysconfig -} - // Route looks up the path that would be used for a given path string. func (b *Backend) Route(path string) *Path { result, _ := b.route(path) diff --git a/logical/system_config.go b/logical/system_config.go index 0f1fb3659..37b77148e 100644 --- a/logical/system_config.go +++ b/logical/system_config.go @@ -15,15 +15,15 @@ type SystemView interface { MaxLeaseTTL() time.Duration } -type DefaultSystemView struct { - DefaultLeaseTTLFunc func() time.Duration - MaxLeaseTTLFunc func() time.Duration +type StaticSystemView struct { + DefaultLeaseTTLVal time.Duration + MaxLeaseTTLVal time.Duration } -func (d *DefaultSystemView) DefaultLeaseTTL() time.Duration { - return d.DefaultLeaseTTLFunc() +func (d *StaticSystemView) DefaultLeaseTTL() time.Duration { + return d.DefaultLeaseTTLVal } -func (d *DefaultSystemView) MaxLeaseTTL() time.Duration { - return d.MaxLeaseTTLFunc() +func (d *StaticSystemView) MaxLeaseTTL() time.Duration { + return d.MaxLeaseTTLVal } diff --git a/vault/core.go b/vault/core.go index d5effc55d..ca9fe8e84 100644 --- a/vault/core.go +++ b/vault/core.go @@ -1577,11 +1577,3 @@ func (c *Core) emitMetrics(stopCh chan struct{}) { } } } - -func (c *Core) DefaultLeaseTTL() time.Duration { - return c.defaultLeaseTTL -} - -func (c *Core) MaxLeaseTTL() time.Duration { - return c.maxLeaseTTL -} diff --git a/vault/mount.go b/vault/mount.go index 153b889ba..fda3bd6ce 100644 --- a/vault/mount.go +++ b/vault/mount.go @@ -466,9 +466,9 @@ func (c *Core) newLogicalBackend(t string, view logical.Storage, conf map[string View: view, Logger: c.logger, Config: conf, - System: &logical.DefaultSystemView{ - DefaultLeaseTTLFunc: c.DefaultLeaseTTL, - MaxLeaseTTLFunc: c.MaxLeaseTTL, + System: &logical.StaticSystemView{ + DefaultLeaseTTLVal: c.defaultLeaseTTL, + MaxLeaseTTLVal: c.maxLeaseTTL, }, }