mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Pass context to backends (#3750)
* Start work on passing context to backends * More work on passing context * Unindent logical system * Unindent token store * Unindent passthrough * Unindent cubbyhole * Fix tests * use requestContext in rollback and expiration managers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/rpc"
|
||||
|
||||
@@ -88,7 +89,7 @@ type RegisterLicenseReply struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
func (b *backendPluginClient) HandleRequest(req *logical.Request) (*logical.Response, error) {
|
||||
func (b *backendPluginClient) HandleRequest(ctx context.Context, req *logical.Request) (*logical.Response, error) {
|
||||
if b.metadataMode {
|
||||
return nil, ErrClientInMetadataMode
|
||||
}
|
||||
@@ -146,7 +147,7 @@ func (b *backendPluginClient) Logger() log.Logger {
|
||||
return b.logger
|
||||
}
|
||||
|
||||
func (b *backendPluginClient) HandleExistenceCheck(req *logical.Request) (bool, bool, error) {
|
||||
func (b *backendPluginClient) HandleExistenceCheck(ctx context.Context, req *logical.Request) (bool, bool, error) {
|
||||
if b.metadataMode {
|
||||
return false, false, ErrClientInMetadataMode
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/rpc"
|
||||
"os"
|
||||
@@ -38,7 +39,7 @@ func (b *backendPluginServer) HandleRequest(args *HandleRequestArgs, reply *Hand
|
||||
storage := &StorageClient{client: b.storageClient}
|
||||
args.Request.Storage = storage
|
||||
|
||||
resp, err := b.backend.HandleRequest(args.Request)
|
||||
resp, err := b.backend.HandleRequest(context.TODO(), args.Request)
|
||||
*reply = HandleRequestReply{
|
||||
Response: resp,
|
||||
Error: wrapError(err),
|
||||
@@ -62,7 +63,7 @@ func (b *backendPluginServer) HandleExistenceCheck(args *HandleExistenceCheckArg
|
||||
storage := &StorageClient{client: b.storageClient}
|
||||
args.Request.Storage = storage
|
||||
|
||||
checkFound, exists, err := b.backend.HandleExistenceCheck(args.Request)
|
||||
checkFound, exists, err := b.backend.HandleExistenceCheck(context.TODO(), args.Request)
|
||||
*reply = HandleExistenceCheckReply{
|
||||
CheckFound: checkFound,
|
||||
Exists: exists,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/rpc"
|
||||
|
||||
"github.com/hashicorp/vault/logical"
|
||||
@@ -26,7 +27,6 @@ func errorPaths(b *backend) []*framework.Path {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *backend) pathErrorRPCRead(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathErrorRPCRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
return nil, rpc.ErrShutdown
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/vault/logical"
|
||||
"github.com/hashicorp/vault/logical/framework"
|
||||
)
|
||||
@@ -20,16 +22,14 @@ func pathInternal(b *backend) *framework.Path {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *backend) pathInternalUpdate(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathInternalUpdate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
value := data.Get("value").(string)
|
||||
b.internal = value
|
||||
// Return the secret
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathInternalRead(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathInternalRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
// Return the secret
|
||||
return &logical.Response{
|
||||
Data: map[string]interface{}{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/vault/logical"
|
||||
@@ -34,7 +35,7 @@ func kvPaths(b *backend) []*framework.Path {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *backend) pathExistenceCheck(req *logical.Request, data *framework.FieldData) (bool, error) {
|
||||
func (b *backend) pathExistenceCheck(ctx context.Context, req *logical.Request, data *framework.FieldData) (bool, error) {
|
||||
out, err := req.Storage.Get(req.Path)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("existence check failed: %v", err)
|
||||
@@ -43,8 +44,7 @@ func (b *backend) pathExistenceCheck(req *logical.Request, data *framework.Field
|
||||
return out != nil, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathKVRead(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathKVRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
entry, err := req.Storage.Get(req.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,8 +64,7 @@ func (b *backend) pathKVRead(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathKVCreateUpdate(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathKVCreateUpdate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
value := data.Get("value").(string)
|
||||
|
||||
entry := &logical.StorageEntry{
|
||||
@@ -86,7 +85,7 @@ func (b *backend) pathKVCreateUpdate(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathKVDelete(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathKVDelete(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
if err := req.Storage.Delete(req.Path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -94,7 +93,7 @@ func (b *backend) pathKVDelete(req *logical.Request, data *framework.FieldData)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathKVList(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathKVList(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
vals, err := req.Storage.List("kv/")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/vault/logical"
|
||||
"github.com/hashicorp/vault/logical/framework"
|
||||
)
|
||||
@@ -15,8 +17,7 @@ func pathSpecial(b *backend) *framework.Path {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *backend) pathSpecialRead(
|
||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
func (b *backend) pathSpecialRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
// Return the secret
|
||||
return &logical.Response{
|
||||
Data: map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user