From 2ae7992a9829b29b4cecdba73d7b5cb3b479863d Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 13 Mar 2015 11:20:36 -0700 Subject: [PATCH] vault: integrate expiration manager with core setup/teardown --- vault/core.go | 3 +++ vault/expiration.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/vault/core.go b/vault/core.go index cea1884571..2b30562eec 100644 --- a/vault/core.go +++ b/vault/core.go @@ -426,6 +426,9 @@ func (c *Core) postUnseal() error { // preSeal is invoked before the barrier is sealed, allowing // for any state teardown required. func (c *Core) preSeal() error { + if err := c.stopExpiration(); err != nil { + return err + } if err := c.unloadMounts(); err != nil { return err } diff --git a/vault/expiration.go b/vault/expiration.go index 0330bb979c..ecc7639bfc 100644 --- a/vault/expiration.go +++ b/vault/expiration.go @@ -41,6 +41,44 @@ func (c *Core) setupExpiration() error { // Create the manager mgr := NewExpirationManager(c.router, view) c.expiration = mgr + + // Restore the existing state + if err := c.expiration.Restore(); err != nil { + return fmt.Errorf("expiration state restore failed: %v", err) + } + + // Start the expiration manager + if err := c.expiration.Start(); err != nil { + return fmt.Errorf("expiration start failed: %v", err) + } + return nil +} + +// stopExpiration is used to stop the expiration manager before +// sealing the Vault. +func (c *Core) stopExpiration() error { + if err := c.expiration.Stop(); err != nil { + return err + } + c.expiration = nil + return nil +} + +// Restore is used to recover the lease states when starting. +// This is used after starting the vault. +func (m *ExpirationManager) Restore() error { + return nil +} + +// Start is used to continue automatic revocation. This +// should only be called when the Vault is unsealed. +func (m *ExpirationManager) Start() error { + return nil +} + +// Stop is used to prevent further automatic revocations. +// This must be called before sealing the view. +func (m *ExpirationManager) Stop() error { return nil }