state/remote: remove consul since we converted that
This commit is contained in:
parent
1492c578de
commit
d3633ab368
|
@ -1,91 +0,0 @@
|
|||
package remote
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
consulapi "github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
||||
func consulFactory(conf map[string]string) (Client, error) {
|
||||
path, ok := conf["path"]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing 'path' configuration")
|
||||
}
|
||||
|
||||
config := consulapi.DefaultConfig()
|
||||
if token, ok := conf["access_token"]; ok && token != "" {
|
||||
config.Token = token
|
||||
}
|
||||
if addr, ok := conf["address"]; ok && addr != "" {
|
||||
config.Address = addr
|
||||
}
|
||||
if scheme, ok := conf["scheme"]; ok && scheme != "" {
|
||||
config.Scheme = scheme
|
||||
}
|
||||
if datacenter, ok := conf["datacenter"]; ok && datacenter != "" {
|
||||
config.Datacenter = datacenter
|
||||
}
|
||||
if auth, ok := conf["http_auth"]; ok && auth != "" {
|
||||
var username, password string
|
||||
if strings.Contains(auth, ":") {
|
||||
split := strings.SplitN(auth, ":", 2)
|
||||
username = split[0]
|
||||
password = split[1]
|
||||
} else {
|
||||
username = auth
|
||||
}
|
||||
config.HttpAuth = &consulapi.HttpBasicAuth{
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
}
|
||||
|
||||
client, err := consulapi.NewClient(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ConsulClient{
|
||||
Client: client,
|
||||
Path: path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConsulClient is a remote client that stores data in Consul.
|
||||
type ConsulClient struct {
|
||||
Client *consulapi.Client
|
||||
Path string
|
||||
}
|
||||
|
||||
func (c *ConsulClient) Get() (*Payload, error) {
|
||||
pair, _, err := c.Client.KV().Get(c.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pair == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
md5 := md5.Sum(pair.Value)
|
||||
return &Payload{
|
||||
Data: pair.Value,
|
||||
MD5: md5[:],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ConsulClient) Put(data []byte) error {
|
||||
kv := c.Client.KV()
|
||||
_, err := kv.Put(&consulapi.KVPair{
|
||||
Key: c.Path,
|
||||
Value: data,
|
||||
}, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ConsulClient) Delete() error {
|
||||
kv := c.Client.KV()
|
||||
_, err := kv.Delete(c.Path, nil)
|
||||
return err
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package remote
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
)
|
||||
|
||||
func TestConsulClient_impl(t *testing.T) {
|
||||
var _ Client = new(ConsulClient)
|
||||
}
|
||||
|
||||
func TestConsulClient(t *testing.T) {
|
||||
acctest.RemoteTestPrecheck(t)
|
||||
|
||||
client, err := consulFactory(map[string]string{
|
||||
"address": "demo.consul.io:80",
|
||||
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
|
||||
testClient(t, client)
|
||||
}
|
|
@ -39,7 +39,6 @@ var BuiltinClients = map[string]Factory{
|
|||
"artifactory": artifactoryFactory,
|
||||
"atlas": atlasFactory,
|
||||
"azure": azureFactory,
|
||||
"consul": consulFactory,
|
||||
"etcd": etcdFactory,
|
||||
"gcs": gcsFactory,
|
||||
"http": httpFactory,
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package remote
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/state"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// TestClient is a generic function to test any client.
|
||||
func TestClient(t *testing.T, c Client) {
|
||||
var buf bytes.Buffer
|
||||
s := state.TestStateInitial()
|
||||
if err := terraform.WriteState(s, &buf); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
data := buf.Bytes()
|
||||
|
||||
if err := c.Put(data); err != nil {
|
||||
t.Fatalf("put: %s", err)
|
||||
}
|
||||
|
||||
p, err := c.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("get: %s", err)
|
||||
}
|
||||
if !bytes.Equal(p.Data, data) {
|
||||
t.Fatalf("bad: %#v", p)
|
||||
}
|
||||
|
||||
if err := c.Delete(); err != nil {
|
||||
t.Fatalf("delete: %s", err)
|
||||
}
|
||||
|
||||
p, err = c.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("get: %s", err)
|
||||
}
|
||||
if p != nil {
|
||||
t.Fatalf("bad: %#v", p)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue