github.com/opentofu/opentofu@v1.7.1/internal/backend/remote-state/inmem/client.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package inmem 7 8 import ( 9 "crypto/md5" 10 11 "github.com/opentofu/opentofu/internal/states/remote" 12 "github.com/opentofu/opentofu/internal/states/statemgr" 13 ) 14 15 // RemoteClient is a remote client that stores data in memory for testing. 16 type RemoteClient struct { 17 Data []byte 18 MD5 []byte 19 Name string 20 } 21 22 func (c *RemoteClient) Get() (*remote.Payload, error) { 23 if c.Data == nil { 24 return nil, nil 25 } 26 27 return &remote.Payload{ 28 Data: c.Data, 29 MD5: c.MD5, 30 }, nil 31 } 32 33 func (c *RemoteClient) Put(data []byte) error { 34 md5 := md5.Sum(data) 35 36 c.Data = data 37 c.MD5 = md5[:] 38 return nil 39 } 40 41 func (c *RemoteClient) Delete() error { 42 c.Data = nil 43 c.MD5 = nil 44 return nil 45 } 46 47 func (c *RemoteClient) Lock(info *statemgr.LockInfo) (string, error) { 48 return locks.lock(c.Name, info) 49 } 50 func (c *RemoteClient) Unlock(id string) error { 51 return locks.unlock(c.Name, id) 52 }