mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	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
		
			
				
	
	
		
			54 lines
		
	
	
		
			947 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			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)
 | 
						|
}
 |