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

72 lines
1.8 KiB
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"
)
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)) {
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,
}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
TLSProvider: tlsProvider,
2017-04-06 19:20:10 +00:00
})
}
// ---- RPC server domain ----
2017-04-24 20:59:12 +00:00
// databasePluginRPCServer implements an RPC version of Database and is run
// inside a plugin. It wraps an underlying implementation of Database.
2017-04-06 19:20:10 +00:00
type databasePluginRPCServer struct {
2017-04-24 20:59:12 +00:00
impl Database
2017-04-06 19:20:10 +00:00
}
func (ds *databasePluginRPCServer) Type(_ struct{}, resp *string) error {
2017-04-12 23:41:06 +00:00
var err error
*resp, err = ds.impl.Type()
return err
2017-04-06 19:20:10 +00:00
}
func (ds *databasePluginRPCServer) CreateUser(args *CreateUserRequest, resp *CreateUserResponse) error {
var err error
resp.Username, resp.Password, err = ds.impl.CreateUser(args.Statements, args.UsernamePrefix, args.Expiration)
2017-04-06 19:20:10 +00:00
return err
}
func (ds *databasePluginRPCServer) RenewUser(args *RenewUserRequest, _ *struct{}) error {
err := ds.impl.RenewUser(args.Statements, args.Username, args.Expiration)
return err
}
func (ds *databasePluginRPCServer) RevokeUser(args *RevokeUserRequest, _ *struct{}) error {
err := ds.impl.RevokeUser(args.Statements, args.Username)
return err
}
func (ds *databasePluginRPCServer) Initialize(args *InitializeRequest, _ *struct{}) error {
err := ds.impl.Initialize(args.Config, args.VerifyConnection)
2017-04-06 19:20:10 +00:00
return err
}
func (ds *databasePluginRPCServer) Close(_ struct{}, _ *struct{}) error {
ds.impl.Close()
return nil
}