Make DefaultSystemView StaticSystemView with statically-configured information. Export this from Framework to make it easy to override for testing.

This commit is contained in:
Jeff Mitchell 2015-08-27 11:25:07 -07:00
parent 7c2bbe4c7f
commit b74fa8c888
4 changed files with 18 additions and 30 deletions

View File

@ -56,10 +56,13 @@ type Backend struct {
// See the built-in AuthRenew helpers in lease.go for common callbacks. // See the built-in AuthRenew helpers in lease.go for common callbacks.
AuthRenew OperationFunc AuthRenew OperationFunc
// 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 logger *log.Logger
once sync.Once once sync.Once
pathsRe []*regexp.Regexp pathsRe []*regexp.Regexp
sysconfig logical.SystemView
} }
// OperationFunc is the callback called for an operation on a path. // 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 // Setup is used to initialize the backend with the initial backend configuration
func (b *Backend) Setup(config *logical.BackendConfig) (logical.Backend, error) { func (b *Backend) Setup(config *logical.BackendConfig) (logical.Backend, error) {
b.logger = config.Logger b.logger = config.Logger
b.sysconfig = config.System b.System = config.System
return b, nil return b, nil
} }
@ -157,13 +160,6 @@ func (b *Backend) Logger() *log.Logger {
return log.New(ioutil.Discard, "", 0) 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. // Route looks up the path that would be used for a given path string.
func (b *Backend) Route(path string) *Path { func (b *Backend) Route(path string) *Path {
result, _ := b.route(path) result, _ := b.route(path)

View File

@ -15,15 +15,15 @@ type SystemView interface {
MaxLeaseTTL() time.Duration MaxLeaseTTL() time.Duration
} }
type DefaultSystemView struct { type StaticSystemView struct {
DefaultLeaseTTLFunc func() time.Duration DefaultLeaseTTLVal time.Duration
MaxLeaseTTLFunc func() time.Duration MaxLeaseTTLVal time.Duration
} }
func (d *DefaultSystemView) DefaultLeaseTTL() time.Duration { func (d *StaticSystemView) DefaultLeaseTTL() time.Duration {
return d.DefaultLeaseTTLFunc() return d.DefaultLeaseTTLVal
} }
func (d *DefaultSystemView) MaxLeaseTTL() time.Duration { func (d *StaticSystemView) MaxLeaseTTL() time.Duration {
return d.MaxLeaseTTLFunc() return d.MaxLeaseTTLVal
} }

View File

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

View File

@ -466,9 +466,9 @@ func (c *Core) newLogicalBackend(t string, view logical.Storage, conf map[string
View: view, View: view,
Logger: c.logger, Logger: c.logger,
Config: conf, Config: conf,
System: &logical.DefaultSystemView{ System: &logical.StaticSystemView{
DefaultLeaseTTLFunc: c.DefaultLeaseTTL, DefaultLeaseTTLVal: c.defaultLeaseTTL,
MaxLeaseTTLFunc: c.MaxLeaseTTL, MaxLeaseTTLVal: c.maxLeaseTTL,
}, },
} }