2015-03-15 21:26:48 +00:00
|
|
|
package logical
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2016-06-06 16:03:08 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/vault/physical"
|
2015-03-15 21:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// InmemStorage implements Storage and stores all data in memory.
|
|
|
|
type InmemStorage struct {
|
2016-06-06 16:03:08 +00:00
|
|
|
phys *physical.InmemBackend
|
2015-03-15 21:26:48 +00:00
|
|
|
|
|
|
|
once sync.Once
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *InmemStorage) List(prefix string) ([]string, error) {
|
|
|
|
s.once.Do(s.init)
|
|
|
|
|
2016-06-06 16:03:08 +00:00
|
|
|
return s.phys.List(prefix)
|
2015-03-15 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *InmemStorage) Get(key string) (*StorageEntry, error) {
|
|
|
|
s.once.Do(s.init)
|
2016-06-06 16:03:08 +00:00
|
|
|
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
|
2015-03-15 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *InmemStorage) Put(entry *StorageEntry) error {
|
|
|
|
s.once.Do(s.init)
|
2016-06-06 16:03:08 +00:00
|
|
|
physEntry := &physical.Entry{
|
|
|
|
Key: entry.Key,
|
|
|
|
Value: entry.Value,
|
|
|
|
}
|
|
|
|
return s.phys.Put(physEntry)
|
2015-03-15 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *InmemStorage) Delete(k string) error {
|
|
|
|
s.once.Do(s.init)
|
2016-06-06 16:03:08 +00:00
|
|
|
return s.phys.Delete(k)
|
2015-03-15 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *InmemStorage) init() {
|
2016-06-06 16:03:08 +00:00
|
|
|
s.phys = physical.NewInmem(nil)
|
2015-03-15 21:26:48 +00:00
|
|
|
}
|