open-vault/sdk/plugin/middleware.go

101 lines
3.1 KiB
Go
Raw Normal View History

package plugin
import (
"context"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/logical"
)
// backendPluginClient implements logical.Backend and is the
// go-plugin client.
type backendTracingMiddleware struct {
logger log.Logger
next logical.Backend
}
// Validate the backendTracingMiddle object satisfies the backend interface
var _ logical.Backend = &backendTracingMiddleware{}
AWS upgrade role entries (#7025) * upgrade aws roles * test upgrade aws roles * Initialize aws credential backend at mount time * add a TODO * create end-to-end test for builtin/credential/aws * fix bug in initializer * improve comments * add Initialize() to logical.Backend * use Initialize() in Core.enableCredentialInternal() * use InitializeRequest to call Initialize() * improve unit testing for framework.Backend * call logical.Backend.Initialize() from all of the places that it needs to be called. * implement backend.proto changes for logical.Backend.Initialize() * persist current role storage version when upgrading aws roles * format comments correctly * improve comments * use postUnseal funcs to initialize backends * simplify test suite * improve test suite * simplify logic in aws role upgrade * simplify aws credential initialization logic * simplify logic in aws role upgrade * use the core's activeContext for initialization * refactor builtin/plugin/Backend * use a goroutine to upgrade the aws roles * misc improvements and cleanup * do not run AWS role upgrade on DR Secondary * always call logical.Backend.Initialize() when loading a plugin. * improve comments * on standbys and DR secondaries we do not want to run any kind of upgrade logic * fix awsVersion struct * clarify aws version upgrade * make the upgrade logic for aws auth more explicit * aws upgrade is now called from a switch * fix fallthrough bug * simplify logic * simplify logic * rename things * introduce currentAwsVersion const to track aws version * improve comments * rearrange things once more * conglomerate things into one function * stub out aws auth initialize e2e test * improve aws auth initialize e2e test * finish aws auth initialize e2e test * tinker with aws auth initialize e2e test * tinker with aws auth initialize e2e test * tinker with aws auth initialize e2e test * fix typo in test suite * simplify logic a tad * rearrange assignment * Fix a few lifecycle related issues in #7025 (#7075) * Fix panic when plugin fails to load
2019-07-05 23:55:40 +00:00
func (b *backendTracingMiddleware) Initialize(ctx context.Context, req *logical.InitializationRequest) (err error) {
defer func(then time.Time) {
b.logger.Trace("initialize", "status", "finished", "err", err, "took", time.Since(then))
}(time.Now())
b.logger.Trace("initialize", "status", "started")
return b.next.Initialize(ctx, req)
}
func (b *backendTracingMiddleware) HandleRequest(ctx context.Context, req *logical.Request) (resp *logical.Response, err error) {
defer func(then time.Time) {
b.logger.Trace("handle request", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
}(time.Now())
b.logger.Trace("handle request", "path", req.Path, "status", "started")
return b.next.HandleRequest(ctx, req)
}
func (b *backendTracingMiddleware) SpecialPaths() *logical.Paths {
defer func(then time.Time) {
b.logger.Trace("special paths", "status", "finished", "took", time.Since(then))
}(time.Now())
b.logger.Trace("special paths", "status", "started")
return b.next.SpecialPaths()
}
func (b *backendTracingMiddleware) System() logical.SystemView {
return b.next.System()
}
func (b *backendTracingMiddleware) Logger() log.Logger {
return b.next.Logger()
}
func (b *backendTracingMiddleware) HandleExistenceCheck(ctx context.Context, req *logical.Request) (found bool, exists bool, err error) {
defer func(then time.Time) {
b.logger.Trace("handle existence check", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
}(time.Now())
b.logger.Trace("handle existence check", "path", req.Path, "status", "started")
return b.next.HandleExistenceCheck(ctx, req)
}
func (b *backendTracingMiddleware) Cleanup(ctx context.Context) {
defer func(then time.Time) {
b.logger.Trace("cleanup", "status", "finished", "took", time.Since(then))
}(time.Now())
b.logger.Trace("cleanup", "status", "started")
b.next.Cleanup(ctx)
}
func (b *backendTracingMiddleware) InvalidateKey(ctx context.Context, key string) {
defer func(then time.Time) {
b.logger.Trace("invalidate key", "key", key, "status", "finished", "took", time.Since(then))
}(time.Now())
b.logger.Trace("invalidate key", "key", key, "status", "started")
b.next.InvalidateKey(ctx, key)
}
func (b *backendTracingMiddleware) Setup(ctx context.Context, config *logical.BackendConfig) (err error) {
defer func(then time.Time) {
b.logger.Trace("setup", "status", "finished", "err", err, "took", time.Since(then))
}(time.Now())
b.logger.Trace("setup", "status", "started")
return b.next.Setup(ctx, config)
}
func (b *backendTracingMiddleware) Type() logical.BackendType {
defer func(then time.Time) {
b.logger.Trace("type", "status", "finished", "took", time.Since(then))
}(time.Now())
b.logger.Trace("type", "status", "started")
return b.next.Type()
}