2015-02-21 20:52:55 +01:00
|
|
|
package remote
|
|
|
|
|
2015-02-22 00:13:28 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-02-21 20:52:55 +01:00
|
|
|
// Client is the interface that must be implemented for a remote state
|
|
|
|
// driver. It supports dumb put/get/delete, and the higher level structs
|
|
|
|
// handle persisting the state properly here.
|
|
|
|
type Client interface {
|
|
|
|
Get() (*Payload, error)
|
|
|
|
Put([]byte) error
|
|
|
|
Delete() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Payload is the return value from the remote state storage.
|
|
|
|
type Payload struct {
|
|
|
|
MD5 []byte
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// Factory is the factory function to create a remote client.
|
|
|
|
type Factory func(map[string]string) (Client, error)
|
2015-02-22 00:13:28 +01:00
|
|
|
|
|
|
|
// NewClient returns a new Client with the given type and configuration.
|
|
|
|
// The client is looked up in the BuiltinClients variable.
|
|
|
|
func NewClient(t string, conf map[string]string) (Client, error) {
|
|
|
|
f, ok := BuiltinClients[t]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unknown remote client type: %s", t)
|
|
|
|
}
|
|
|
|
|
|
|
|
return f(conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BuiltinClients is the list of built-in clients that can be used with
|
|
|
|
// NewClient.
|
|
|
|
var BuiltinClients = map[string]Factory{
|
2016-09-04 00:38:43 +02:00
|
|
|
"artifactory": artifactoryFactory,
|
2015-10-29 14:33:09 +01:00
|
|
|
"atlas": atlasFactory,
|
2016-06-10 20:04:40 +02:00
|
|
|
"azure": azureFactory,
|
2015-10-29 14:33:09 +01:00
|
|
|
"consul": consulFactory,
|
|
|
|
"etcd": etcdFactory,
|
2016-05-21 07:59:30 +02:00
|
|
|
"gcs": gcsFactory,
|
2015-10-29 14:33:09 +01:00
|
|
|
"http": httpFactory,
|
2016-09-04 00:38:43 +02:00
|
|
|
"local": fileFactory,
|
2015-10-29 14:33:09 +01:00
|
|
|
"s3": s3Factory,
|
|
|
|
"swift": swiftFactory,
|
2016-09-13 20:49:09 +02:00
|
|
|
"manta": mantaFactory,
|
2015-02-22 00:13:28 +01:00
|
|
|
}
|