Skip to content

Commit

Permalink
Add an option to log all ops to inmem (hashicorp#5306)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai authored Sep 7, 2018
1 parent 3011228 commit 7d564c5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions physical/inmem/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package inmem
import (
"context"
"errors"
"os"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -40,6 +41,7 @@ type InmemBackend struct {
failPut *uint32
failDelete *uint32
failList *uint32
logOps bool
}

type TransactionalInmemBackend struct {
Expand All @@ -56,6 +58,7 @@ func NewInmem(_ map[string]string, logger log.Logger) (physical.Backend, error)
failPut: new(uint32),
failDelete: new(uint32),
failList: new(uint32),
logOps: os.Getenv("VAULT_INMEM_LOG_ALL_OPS") != "",
}
return in, nil
}
Expand All @@ -72,6 +75,7 @@ func NewTransactionalInmem(_ map[string]string, logger log.Logger) (physical.Bac
failPut: new(uint32),
failDelete: new(uint32),
failList: new(uint32),
logOps: os.Getenv("VAULT_INMEM_LOG_ALL_OPS") != "",
},
}
return in, nil
Expand All @@ -89,6 +93,9 @@ func (i *InmemBackend) Put(ctx context.Context, entry *physical.Entry) error {
}

func (i *InmemBackend) PutInternal(ctx context.Context, entry *physical.Entry) error {
if i.logOps {
i.logger.Trace("put", "key", entry.Key)
}
if atomic.LoadUint32(i.failPut) != 0 {
return PutDisabledError
}
Expand Down Expand Up @@ -123,6 +130,9 @@ func (i *InmemBackend) Get(ctx context.Context, key string) (*physical.Entry, er
}

func (i *InmemBackend) GetInternal(ctx context.Context, key string) (*physical.Entry, error) {
if i.logOps {
i.logger.Trace("get", "key", key)
}
if atomic.LoadUint32(i.failGet) != 0 {
return nil, GetDisabledError
}
Expand Down Expand Up @@ -162,6 +172,9 @@ func (i *InmemBackend) Delete(ctx context.Context, key string) error {
}

func (i *InmemBackend) DeleteInternal(ctx context.Context, key string) error {
if i.logOps {
i.logger.Trace("delete", "key", key)
}
if atomic.LoadUint32(i.failDelete) != 0 {
return DeleteDisabledError
}
Expand Down Expand Up @@ -196,6 +209,9 @@ func (i *InmemBackend) List(ctx context.Context, prefix string) ([]string, error
}

func (i *InmemBackend) ListInternal(ctx context.Context, prefix string) ([]string, error) {
if i.logOps {
i.logger.Trace("list", "prefix", prefix)
}
if atomic.LoadUint32(i.failList) != 0 {
return nil, ListDisabledError
}
Expand Down

0 comments on commit 7d564c5

Please sign in to comment.