vault/sdk/database/dbplugin/v5/plugin_server.go
Vault Automation 0c6c13dd38
license: update headers to IBM Corp. (#10229) (#10233)
* license: update headers to IBM Corp.
* `make proto`
* update offset because source file changed

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-10-21 15:20:20 -06:00

86 lines
1.6 KiB
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: MPL-2.0
package dbplugin
import (
"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) {
plugin.Serve(ServeConfig(db))
}
func ServeConfig(db Database) *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: {
"database": &GRPCDatabasePlugin{
Impl: db,
},
},
}
conf := &plugin.ServeConfig{
HandshakeConfig: HandshakeConfig,
VersionedPlugins: pluginSets,
GRPCServer: plugin.DefaultGRPCServer,
}
return conf
}
func ServeMultiplex(factory Factory) {
plugin.Serve(ServeConfigMultiplex(factory))
}
func ServeConfigMultiplex(factory Factory) *plugin.ServeConfig {
err := pluginutil.OptionallyEnableMlock()
if err != nil {
fmt.Println(err)
return nil
}
db, err := factory()
if err != nil {
fmt.Println(err)
return nil
}
database := db.(Database)
// pluginSets is the map of plugins we can dispense.
pluginSets := map[int]plugin.PluginSet{
5: {
"database": &GRPCDatabasePlugin{
Impl: database,
},
},
6: {
"database": &GRPCDatabasePlugin{
FactoryFunc: factory,
},
},
}
conf := &plugin.ServeConfig{
HandshakeConfig: HandshakeConfig,
VersionedPlugins: pluginSets,
GRPCServer: plugin.DefaultGRPCServer,
}
return conf
}