385140ee6b
* Use version to determine plugin protocol to use * Remove field from ServeOpts * Fix missing assignment, handle errors * contraint -> constraint * Inject the version string from the vault side * Fix the version check * Add grpc support check to database plugins * Default to use grpc unless missing env var or fail on contraint check * Add GRPCSupport test * Add greater than test case * Add go-version dep
40 lines
910 B
Go
40 lines
910 B
Go
package dbplugin
|
|
|
|
import (
|
|
"crypto/tls"
|
|
|
|
"github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/vault/helper/pluginutil"
|
|
)
|
|
|
|
// Serve is called from within a plugin and wraps the provided
|
|
// Database implementation in a databasePluginRPCServer object and starts a
|
|
// RPC server.
|
|
func Serve(db Database, tlsProvider func() (*tls.Config, error)) {
|
|
plugin.Serve(ServeConfig(db, tlsProvider))
|
|
}
|
|
|
|
func ServeConfig(db Database, tlsProvider func() (*tls.Config, error)) *plugin.ServeConfig {
|
|
dbPlugin := &DatabasePlugin{
|
|
impl: db,
|
|
}
|
|
|
|
// pluginMap is the map of plugins we can dispense.
|
|
var pluginMap = map[string]plugin.Plugin{
|
|
"database": dbPlugin,
|
|
}
|
|
|
|
conf := &plugin.ServeConfig{
|
|
HandshakeConfig: handshakeConfig,
|
|
Plugins: pluginMap,
|
|
TLSProvider: tlsProvider,
|
|
GRPCServer: plugin.DefaultGRPCServer,
|
|
}
|
|
|
|
if !pluginutil.GRPCSupport() {
|
|
conf.GRPCServer = nil
|
|
}
|
|
|
|
return conf
|
|
}
|