mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-20 06:01:10 +02:00
The result will still pass gofmtcheck and won't trigger additional changes if someone isn't using goimports, but it will avoid the piecemeal imports changes we've been seeing.
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package dbplugin
|
|
|
|
import (
|
|
"crypto/tls"
|
|
|
|
plugin "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 {
|
|
// 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,
|
|
},
|
|
},
|
|
}
|
|
|
|
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
|
|
}
|