Add compile tests to verify physical stores satisfy the correct interfaces (#3820)

This commit is contained in:
Brian Kassouf
2018-01-19 17:44:24 -08:00
committed by GitHub
parent 2fea072515
commit fbe5f87278
20 changed files with 76 additions and 27 deletions

View File

@@ -32,6 +32,9 @@ type AzureBackend struct {
permitPool *physical.PermitPool permitPool *physical.PermitPool
} }
// Verify AzureBackend satisfies the correct interfaces
var _ physical.Backend = (*AzureBackend)(nil)
// NewAzureBackend constructs an Azure backend using a pre-existing // NewAzureBackend constructs an Azure backend using a pre-existing
// bucket. Credentials can be provided to the backend, sourced // bucket. Credentials can be provided to the backend, sourced
// from the environment, AWS credential files or by IAM role. // from the environment, AWS credential files or by IAM role.

View File

@@ -33,7 +33,11 @@ type TransactionalCache struct {
Transactional Transactional
} }
var _ Purgable = &Cache{} // Verify Cache satisfies the correct interfaces
var _ Purgable = (*Cache)(nil)
var _ Backend = (*Cache)(nil)
var _ Transactional = (*TransactionalCache)(nil)
var _ Purgable = (*TransactionalCache)(nil)
// NewCache returns a physical cache of the given size. // NewCache returns a physical cache of the given size.
// If no size is provided, the default size is used. // If no size is provided, the default size is used.

View File

@@ -26,6 +26,9 @@ type CassandraBackend struct {
logger log.Logger logger log.Logger
} }
// Verify CassandraBackend satisfies the correct interfaces
var _ physical.Backend = (*CassandraBackend)(nil)
// NewCassandraBackend constructs a Cassandra backend using a pre-existing // NewCassandraBackend constructs a Cassandra backend using a pre-existing
// keyspace and table. // keyspace and table.
func NewCassandraBackend(conf map[string]string, logger log.Logger) (physical.Backend, error) { func NewCassandraBackend(conf map[string]string, logger log.Logger) (physical.Backend, error) {

View File

@@ -20,7 +20,9 @@ import (
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
var _ physical.Transactional = &CockroachDBBackend{} // Verify CockroachDBBackend satisfies the correct interfaces
var _ physical.Backend = (*CockroachDBBackend)(nil)
var _ physical.Transactional = (*CockroachDBBackend)(nil)
// CockroachDBBackend Backend is a physical backend that stores data // CockroachDBBackend Backend is a physical backend that stores data
// within a CockroachDB database. // within a CockroachDB database.

View File

@@ -67,11 +67,11 @@ const (
type notifyEvent struct{} type notifyEvent struct{}
// Verify interfaces are satisfied // Verify ConsulBackend satisfies the correct interfaces
var _ physical.Backend = &ConsulBackend{} var _ physical.Backend = (*ConsulBackend)(nil)
var _ physical.HABackend = &ConsulBackend{} var _ physical.HABackend = (*ConsulBackend)(nil)
var _ physical.Lock = &ConsulLock{} var _ physical.Lock = (*ConsulLock)(nil)
var _ physical.Transactional = &ConsulBackend{} var _ physical.Transactional = (*ConsulBackend)(nil)
// ConsulBackend is a physical backend that stores data at specific // ConsulBackend is a physical backend that stores data at specific
// prefix within Consul. It is used for most production situations as // prefix within Consul. It is used for most production situations as

View File

@@ -27,6 +27,11 @@ type CouchDBBackend struct {
permitPool *physical.PermitPool permitPool *physical.PermitPool
} }
// Verify CouchDBBackend satisfies the correct interfaces
var _ physical.Backend = (*CouchDBBackend)(nil)
var _ physical.PseudoTransactional = (*CouchDBBackend)(nil)
var _ physical.PseudoTransactional = (*TransactionalCouchDBBackend)(nil)
type couchDBClient struct { type couchDBClient struct {
endpoint string endpoint string
username string username string
@@ -254,8 +259,6 @@ func (m *CouchDBBackend) List(ctx context.Context, prefix string) ([]string, err
return out, nil return out, nil
} }
var _ physical.PseudoTransactional = &TransactionalCouchDBBackend{}
// TransactionalCouchDBBackend creates a couchdb backend that forces all operations to happen // TransactionalCouchDBBackend creates a couchdb backend that forces all operations to happen
// in serial // in serial
type TransactionalCouchDBBackend struct { type TransactionalCouchDBBackend struct {

View File

@@ -69,6 +69,11 @@ const (
DynamoDBWatchRetryInterval = 5 * time.Second DynamoDBWatchRetryInterval = 5 * time.Second
) )
// Verify DynamoDBBackend satisfies the correct interfaces
var _ physical.Backend = (*DynamoDBBackend)(nil)
var _ physical.HABackend = (*DynamoDBBackend)(nil)
var _ physical.Lock = (*DynamoDBLock)(nil)
// DynamoDBBackend is a physical backend that stores data in // DynamoDBBackend is a physical backend that stores data in
// a DynamoDB table. It can be run in high-availability mode // a DynamoDB table. It can be run in high-availability mode
// as DynamoDB has locking capabilities. // as DynamoDB has locking capabilities.

View File

@@ -55,10 +55,10 @@ type Etcd2Backend struct {
haEnabled bool haEnabled bool
} }
// Verify interfaces are satisfied // Verify Etcd2Backend satisfies the correct interfaces
var _ physical.Backend = &Etcd2Backend{} var _ physical.Backend = (*Etcd2Backend)(nil)
var _ physical.HABackend = &Etcd2Backend{} var _ physical.HABackend = (*Etcd2Backend)(nil)
var _ physical.Lock = &Etcd2Lock{} var _ physical.Lock = (*Etcd2Lock)(nil)
func newEtcd2Backend(conf map[string]string, logger log.Logger) (physical.Backend, error) { func newEtcd2Backend(conf map[string]string, logger log.Logger) (physical.Backend, error) {
// Get the etcd path form the configuration. // Get the etcd path form the configuration.

View File

@@ -41,10 +41,10 @@ const (
etcd3RequestTimeout = 5 * time.Second etcd3RequestTimeout = 5 * time.Second
) )
// Verify interfaces are satisfied // Verify EtcdBackend satisfies the correct interfaces
var _ physical.Backend = &EtcdBackend{} var _ physical.Backend = (*EtcdBackend)(nil)
var _ physical.HABackend = &EtcdBackend{} var _ physical.HABackend = (*EtcdBackend)(nil)
var _ physical.Lock = &EtcdLock{} var _ physical.Lock = (*EtcdLock)(nil)
// newEtcd3Backend constructs a etcd3 backend. // newEtcd3Backend constructs a etcd3 backend.
func newEtcd3Backend(conf map[string]string, logger log.Logger) (physical.Backend, error) { func newEtcd3Backend(conf map[string]string, logger log.Logger) (physical.Backend, error) {

View File

@@ -17,9 +17,10 @@ import (
"github.com/hashicorp/vault/physical" "github.com/hashicorp/vault/physical"
) )
// Verify interfaces are satisfied // Verify FileBackend satisfies the correct interfaces
var _ physical.Backend = &FileBackend{} var _ physical.Backend = (*FileBackend)(nil)
var _ physical.Transactional = &TransactionalFileBackend{} var _ physical.Transactional = (*TransactionalFileBackend)(nil)
var _ physical.PseudoTransactional = (*FileBackend)(nil)
// FileBackend is a physical backend that stores data on disk // FileBackend is a physical backend that stores data on disk
// at a given file path. It can be used for durable single server // at a given file path. It can be used for durable single server

View File

@@ -20,8 +20,8 @@ import (
"google.golang.org/api/option" "google.golang.org/api/option"
) )
// Verify interfaces are satisfied // Verify GCSBackend satisfies the correct interfaces
var _ physical.Backend = &GCSBackend{} var _ physical.Backend = (*GCSBackend)(nil)
// GCSBackend is a physical backend that stores data // GCSBackend is a physical backend that stores data
// within an Google Cloud Storage bucket. // within an Google Cloud Storage bucket.

View File

@@ -12,11 +12,12 @@ import (
) )
// Verify interfaces are satisfied // Verify interfaces are satisfied
var _ physical.Backend = &InmemBackend{} var _ physical.Backend = (*InmemBackend)(nil)
var _ physical.HABackend = &InmemHABackend{} var _ physical.HABackend = (*InmemHABackend)(nil)
var _ physical.Lock = &InmemLock{} var _ physical.HABackend = (*TransactionalInmemHABackend)(nil)
var _ physical.Transactional = &TransactionalInmemBackend{} var _ physical.Lock = (*InmemLock)(nil)
var _ physical.Transactional = &TransactionalInmemHABackend{} var _ physical.Transactional = (*TransactionalInmemBackend)(nil)
var _ physical.Transactional = (*TransactionalInmemHABackend)(nil)
// InmemBackend is an in-memory only physical backend. It is useful // InmemBackend is an in-memory only physical backend. It is useful
// for testing and development situations where the data is not // for testing and development situations where the data is not

View File

@@ -28,6 +28,10 @@ type TransactionalLatencyInjector struct {
Transactional Transactional
} }
// Verify LatencyInjector satisfies the correct interfaces
var _ Backend = (*LatencyInjector)(nil)
var _ Transactional = (*TransactionalLatencyInjector)(nil)
// NewLatencyInjector returns a wrapped physical backend to simulate latency // NewLatencyInjector returns a wrapped physical backend to simulate latency
func NewLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *LatencyInjector { func NewLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *LatencyInjector {
if jitter < 0 || jitter > 100 { if jitter < 0 || jitter > 100 {

View File

@@ -17,6 +17,9 @@ import (
log "github.com/mgutz/logxi/v1" log "github.com/mgutz/logxi/v1"
) )
// Verify MSSQLBackend satisfies the correct interfaces
var _ physical.Backend = (*MSSQLBackend)(nil)
type MSSQLBackend struct { type MSSQLBackend struct {
dbTable string dbTable string
client *sql.DB client *sql.DB

View File

@@ -22,6 +22,9 @@ import (
"github.com/hashicorp/vault/physical" "github.com/hashicorp/vault/physical"
) )
// Verify MySQLBackend satisfies the correct interfaces
var _ physical.Backend = (*MySQLBackend)(nil)
// Unreserved tls key // Unreserved tls key
// Reserved values are "true", "false", "skip-verify" // Reserved values are "true", "false", "skip-verify"
const mysqlTLSKey = "default" const mysqlTLSKey = "default"

View File

@@ -16,6 +16,9 @@ type View struct {
prefix string prefix string
} }
// Verify View satisfies the correct interfaces
var _ Backend = (*View)(nil)
// NewView takes an underlying physical backend and returns // NewView takes an underlying physical backend and returns
// a view of it that can only operate with the given prefix. // a view of it that can only operate with the given prefix.
func NewView(backend Backend, prefix string) *View { func NewView(backend Backend, prefix string) *View {

View File

@@ -16,6 +16,9 @@ import (
"github.com/lib/pq" "github.com/lib/pq"
) )
// Verify PostgreSQLBackend satisfies the correct interfaces
var _ physical.Backend = (*PostgreSQLBackend)(nil)
// PostgreSQL Backend is a physical backend that stores data // PostgreSQL Backend is a physical backend that stores data
// within a PostgreSQL database. // within a PostgreSQL database.
type PostgreSQLBackend struct { type PostgreSQLBackend struct {

View File

@@ -27,6 +27,9 @@ import (
"github.com/hashicorp/vault/physical" "github.com/hashicorp/vault/physical"
) )
// Verify S3Backend satisfies the correct interfaces
var _ physical.Backend = (*S3Backend)(nil)
// S3Backend is a physical backend that stores data // S3Backend is a physical backend that stores data
// within an S3 bucket. // within an S3 bucket.
type S3Backend struct { type S3Backend struct {

View File

@@ -19,6 +19,9 @@ import (
"github.com/ncw/swift" "github.com/ncw/swift"
) )
// Verify SwiftBackend satisfies the correct interfaces
var _ physical.Backend = (*SwiftBackend)(nil)
// SwiftBackend is a physical backend that stores data // SwiftBackend is a physical backend that stores data
// within an OpenStack Swift container. // within an OpenStack Swift container.
type SwiftBackend struct { type SwiftBackend struct {

View File

@@ -24,6 +24,11 @@ const (
ZKNodeFilePrefix = "_" ZKNodeFilePrefix = "_"
) )
// Verify ZooKeeperBackend satisfies the correct interfaces
var _ physical.Backend = (*ZooKeeperBackend)(nil)
var _ physical.HABackend = (*ZooKeeperBackend)(nil)
var _ physical.Lock = (*ZooKeeperHALock)(nil)
// ZooKeeperBackend is a physical backend that stores data at specific // ZooKeeperBackend is a physical backend that stores data at specific
// prefix within ZooKeeper. It is used in production situations as // prefix within ZooKeeper. It is used in production situations as
// it allows Vault to run on multiple machines in a highly-available manner. // it allows Vault to run on multiple machines in a highly-available manner.