refactor database plugin SDK (#29479)

* prepare for enterprise database plugin SDK development
This commit is contained in:
Thy Ton
2025-02-03 08:50:33 -08:00
committed by GitHub
parent cda9ad3491
commit 193796bfc9
16 changed files with 270 additions and 166 deletions

View File

@@ -12,6 +12,7 @@ import (
"time"
"github.com/golang/protobuf/ptypes"
"github.com/hashicorp/vault/sdk/database/dbplugin/v5/proto"
"github.com/hashicorp/vault/sdk/helper/pluginutil"
"github.com/hashicorp/vault/sdk/logical"
@@ -25,6 +26,7 @@ var (
)
type gRPCClient struct {
entGRPCClient
client proto.DatabaseClient
versionClient logical.PluginVersionClient
doneCtx context.Context
@@ -285,20 +287,6 @@ func (c gRPCClient) Type() (string, error) {
return typeResp.GetType(), nil
}
func (c gRPCClient) Close() error {
ctx, cancel := getContextWithTimeout(pluginutil.PluginGRPCTimeoutClose)
defer cancel()
_, err := c.client.Close(ctx, &proto.Empty{})
if err != nil {
if c.doneCtx.Err() != nil {
return ErrPluginShutdown
}
return err
}
return nil
}
func getContextWithTimeout(env string) (context.Context, context.CancelFunc) {
timeout := 1 // default timeout
if envTimeout, err := strconv.Atoi(os.Getenv(env)); err == nil && envTimeout > 0 {