open-vault/builtin/logical/database/dbplugin/server.go

40 lines
910 B
Go
Raw Normal View History

2017-04-06 19:20:10 +00:00
package dbplugin
import (
"crypto/tls"
2017-04-11 00:12:52 +00:00
2017-04-06 19:20:10 +00:00
"github.com/hashicorp/go-plugin"
"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.
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 {
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,
}
conf := &plugin.ServeConfig{
2017-04-06 19:20:10 +00:00
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
TLSProvider: tlsProvider,
GRPCServer: plugin.DefaultGRPCServer,
}
if !pluginutil.GRPCSupport() {
conf.GRPCServer = nil
}
return conf
2017-04-06 19:20:10 +00:00
}