logical/framework: rollback needs to have access to request for storage

This commit is contained in:
Mitchell Hashimoto 2015-03-21 11:03:59 +01:00
parent a78b7207b9
commit a54d90ac1f
2 changed files with 11 additions and 4 deletions

View file

@ -36,7 +36,11 @@ type Backend struct {
// Rollback is called when a WAL entry (see wal.go) has to be rolled
// back. It is called with the data from the entry. Boolean true should
// be returned on success. Errors should just be logged.
Rollback func(kind string, data interface{}) bool
//
// RollbackMinAge is the minimum age of a WAL entry before it is attempted
// to be rolled back. This should be longer than the maximum time it takes
// to successfully create a secret.
Rollback RollbackFunc
RollbackMinAge time.Duration
once sync.Once
@ -46,6 +50,9 @@ type Backend struct {
// OperationFunc is the callback called for an operation on a path.
type OperationFunc func(*logical.Request, *FieldData) (*logical.Response, error)
// RollbackFunc is the callback for rollbacks.
type RollbackFunc func(*logical.Request, string, interface{}) bool
// logical.Backend impl.
func (b *Backend) HandleRequest(req *logical.Request) (*logical.Response, error) {
// Check for special cased global operations. These don't route
@ -235,7 +242,7 @@ func (b *Backend) handleRollback(
}
// Attempt a rollback
if b.Rollback(entry.Kind, entry.Data) {
if b.Rollback(req, entry.Kind, entry.Data) {
if err := DeleteWAL(req.Storage, k); err != nil {
merr = multierror.Append(merr, err)
}

View file

@ -189,7 +189,7 @@ func TestBackendHandleRequest_revoke(t *testing.T) {
func TestBackendHandleRequest_rollback(t *testing.T) {
var called uint32
callback := func(kind string, data interface{}) bool {
callback := func(req *logical.Request, kind string, data interface{}) bool {
if data == "foo" {
atomic.AddUint32(&called, 1)
}
@ -224,7 +224,7 @@ func TestBackendHandleRequest_rollback(t *testing.T) {
func TestBackendHandleRequest_rollbackMinAge(t *testing.T) {
var called uint32
callback := func(kind string, data interface{}) bool {
callback := func(req *logical.Request, kind string, data interface{}) bool {
if data == "foo" {
atomic.AddUint32(&called, 1)
}