github.com/sathish1597/hashicorp-terraform@v0.11.12-beta1/backend/remote-state/inmem/client.go (about)

     1  package inmem
     2  
     3  import (
     4  	"crypto/md5"
     5  
     6  	"github.com/hashicorp/terraform/state"
     7  	"github.com/hashicorp/terraform/state/remote"
     8  )
     9  
    10  // RemoteClient is a remote client that stores data in memory for testing.
    11  type RemoteClient struct {
    12  	Data []byte
    13  	MD5  []byte
    14  	Name string
    15  }
    16  
    17  func (c *RemoteClient) Get() (*remote.Payload, error) {
    18  	if c.Data == nil {
    19  		return nil, nil
    20  	}
    21  
    22  	return &remote.Payload{
    23  		Data: c.Data,
    24  		MD5:  c.MD5,
    25  	}, nil
    26  }
    27  
    28  func (c *RemoteClient) Put(data []byte) error {
    29  	md5 := md5.Sum(data)
    30  
    31  	c.Data = data
    32  	c.MD5 = md5[:]
    33  	return nil
    34  }
    35  
    36  func (c *RemoteClient) Delete() error {
    37  	c.Data = nil
    38  	c.MD5 = nil
    39  	return nil
    40  }
    41  
    42  func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
    43  	return locks.lock(c.Name, info)
    44  }
    45  func (c *RemoteClient) Unlock(id string) error {
    46  	return locks.unlock(c.Name, id)
    47  }