2017-04-06 19:20:10 +00:00
|
|
|
package dbplugin
|
|
|
|
|
|
|
|
import (
|
2017-05-02 21:40:11 +00:00
|
|
|
"crypto/tls"
|
2017-04-11 00:12:52 +00:00
|
|
|
|
2017-04-06 19:20:10 +00:00
|
|
|
"github.com/hashicorp/go-plugin"
|
2018-01-23 22:29:26 +00:00
|
|
|
"github.com/hashicorp/vault/helper/pluginutil"
|
2017-04-06 19:20:10 +00:00
|
|
|
)
|
|
|
|
|
2017-05-02 09:00:39 +00:00
|
|
|
// Serve is called from within a plugin and wraps the provided
|
2017-04-24 20:59:12 +00:00
|
|
|
// Database implementation in a databasePluginRPCServer object and starts a
|
2017-04-06 19:20:10 +00:00
|
|
|
// RPC server.
|
2017-05-02 21:40:11 +00:00
|
|
|
func Serve(db Database, tlsProvider func() (*tls.Config, error)) {
|
2017-12-14 22:03:11 +00:00
|
|
|
plugin.Serve(ServeConfig(db, tlsProvider))
|
|
|
|
}
|
|
|
|
|
|
|
|
func ServeConfig(db Database, tlsProvider func() (*tls.Config, error)) *plugin.ServeConfig {
|
2017-04-06 19:20:10 +00:00
|
|
|
dbPlugin := &DatabasePlugin{
|
|
|
|
impl: db,
|
|
|
|
}
|
|
|
|
|
|
|
|
// pluginMap is the map of plugins we can dispense.
|
|
|
|
var pluginMap = map[string]plugin.Plugin{
|
|
|
|
"database": dbPlugin,
|
|
|
|
}
|
|
|
|
|
2018-01-23 22:29:26 +00:00
|
|
|
conf := &plugin.ServeConfig{
|
2017-04-06 19:20:10 +00:00
|
|
|
HandshakeConfig: handshakeConfig,
|
|
|
|
Plugins: pluginMap,
|
2017-05-02 21:40:11 +00:00
|
|
|
TLSProvider: tlsProvider,
|
2017-12-14 22:03:11 +00:00
|
|
|
GRPCServer: plugin.DefaultGRPCServer,
|
|
|
|
}
|
2018-01-23 22:29:26 +00:00
|
|
|
|
|
|
|
if !pluginutil.GRPCSupport() {
|
|
|
|
conf.GRPCServer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf
|
2017-04-06 19:20:10 +00:00
|
|
|
}
|