mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-12 17:47:02 +02:00
This is part 1 of 4 for renaming the `newdbplugin` package. This copies the existing package to the new location but keeps the current one in place so we can migrate the existing references over more easily.
43 lines
975 B
Go
43 lines
975 B
Go
package dbplugin
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/vault/sdk/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 {
|
|
err := pluginutil.OptionallyEnableMlock()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return nil
|
|
}
|
|
|
|
// pluginSets is the map of plugins we can dispense.
|
|
pluginSets := map[int]plugin.PluginSet{
|
|
5: plugin.PluginSet{
|
|
"database": &GRPCDatabasePlugin{
|
|
Impl: db,
|
|
},
|
|
},
|
|
}
|
|
|
|
conf := &plugin.ServeConfig{
|
|
HandshakeConfig: handshakeConfig,
|
|
VersionedPlugins: pluginSets,
|
|
GRPCServer: plugin.DefaultGRPCServer,
|
|
TLSProvider: tlsProvider,
|
|
}
|
|
|
|
return conf
|
|
}
|