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

50 lines
1.2 KiB
Go
Raw Normal View History

2017-04-06 15:20:10 -04:00
package dbplugin
import (
"crypto/tls"
2017-04-10 20:12:52 -04:00
2017-04-06 15:20:10 -04:00
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/vault/helper/pluginutil"
2017-04-06 15:20:10 -04:00
)
2017-05-02 05:00:39 -04:00
// Serve is called from within a plugin and wraps the provided
2017-04-24 16:59:12 -04:00
// Database implementation in a databasePluginRPCServer object and starts a
2017-04-06 15:20:10 -04: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 {
// pluginSets is the map of plugins we can dispense.
pluginSets := map[int]plugin.PluginSet{
3: plugin.PluginSet{
"database": &DatabasePlugin{
GRPCDatabasePlugin: &GRPCDatabasePlugin{
Impl: db,
},
},
},
4: plugin.PluginSet{
"database": &GRPCDatabasePlugin{
Impl: db,
},
},
2017-04-06 15:20:10 -04:00
}
conf := &plugin.ServeConfig{
HandshakeConfig: handshakeConfig,
VersionedPlugins: pluginSets,
TLSProvider: tlsProvider,
GRPCServer: plugin.DefaultGRPCServer,
}
// If we do not have gRPC support fallback to version 3
// Remove this block in 0.13
if !pluginutil.GRPCSupport() {
conf.GRPCServer = nil
delete(conf.VersionedPlugins, 4)
}
return conf
2017-04-06 15:20:10 -04:00
}