open-vault/logical/storage_inmem.go
Jeff Mitchell 8f437d6142 Make logical.InmemStorage a wrapper around physical.InmemBackend.
This:

* Allows removing LockingInmemStorage since the physical backend already
  locks properly
* Makes listing work properly by adhering to expected semantics of only
  listing up to the next prefix separator
* Reduces duplicated code
2016-06-06 12:03:08 -04:00

54 lines
947 B
Go

package logical
import (
"sync"
"github.com/hashicorp/vault/physical"
)
// InmemStorage implements Storage and stores all data in memory.
type InmemStorage struct {
phys *physical.InmemBackend
once sync.Once
}
func (s *InmemStorage) List(prefix string) ([]string, error) {
s.once.Do(s.init)
return s.phys.List(prefix)
}
func (s *InmemStorage) Get(key string) (*StorageEntry, error) {
s.once.Do(s.init)
entry, err := s.phys.Get(key)
if err != nil {
return nil, err
}
if entry == nil {
return nil, nil
}
return &StorageEntry{
Key: entry.Key,
Value: entry.Value,
}, nil
}
func (s *InmemStorage) Put(entry *StorageEntry) error {
s.once.Do(s.init)
physEntry := &physical.Entry{
Key: entry.Key,
Value: entry.Value,
}
return s.phys.Put(physEntry)
}
func (s *InmemStorage) Delete(k string) error {
s.once.Do(s.init)
return s.phys.Delete(k)
}
func (s *InmemStorage) init() {
s.phys = physical.NewInmem(nil)
}