Add cleanup functions to multiple DB backends. (#2313)

Ensure it's called on unmount, not just for seal.
This commit is contained in:
Jeff Mitchell 2017-02-01 14:05:25 -05:00 committed by GitHub
parent 67410ab230
commit 47274eca88
4 changed files with 15 additions and 1 deletions

View File

@ -30,6 +30,10 @@ func Backend() *backend {
Secrets: []*framework.Secret{ Secrets: []*framework.Secret{
secretCreds(&b), secretCreds(&b),
}, },
Clean: func() {
b.ResetDB(nil)
},
} }
return &b return &b

View File

@ -31,6 +31,8 @@ func Backend() *backend {
Secrets: []*framework.Secret{ Secrets: []*framework.Secret{
secretCreds(&b), secretCreds(&b),
}, },
Clean: b.ResetDB,
} }
return &b return &b

View File

@ -31,6 +31,8 @@ func Backend() *backend {
Secrets: []*framework.Secret{ Secrets: []*framework.Secret{
secretCreds(&b), secretCreds(&b),
}, },
Clean: b.ResetDB,
} }
return &b return &b

View File

@ -256,6 +256,12 @@ func (c *Core) unmount(path string) (bool, error) {
return true, err return true, err
} }
// Call cleanup function if it exists
b, ok := c.router.root.Get(path)
if ok {
b.(*routeEntry).backend.Cleanup()
}
// Unmount the backend entirely // Unmount the backend entirely
if err := c.router.Unmount(path); err != nil { if err := c.router.Unmount(path); err != nil {
return true, err return true, err
@ -271,7 +277,7 @@ func (c *Core) unmount(path string) (bool, error) {
return true, err return true, err
} }
if c.logger.IsInfo() { if c.logger.IsInfo() {
c.logger.Info("core: successful unmounted", "path", path) c.logger.Info("core: successfully unmounted", "path", path)
} }
return true, nil return true, nil
} }