Make DefaultSystemView StaticSystemView with statically-configured information. Export this from Framework to make it easy to override for testing.
This commit is contained in:
parent
7c2bbe4c7f
commit
b74fa8c888
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue