2018-01-18 21:49:20 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-01-18 21:49:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// backendPluginClient implements logical.Backend and is the
|
|
|
|
// go-plugin client.
|
|
|
|
type backendTracingMiddleware struct {
|
2018-04-03 00:46:59 +00:00
|
|
|
logger log.Logger
|
2018-01-18 21:49:20 +00:00
|
|
|
|
|
|
|
next logical.Backend
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
// Validate the backendTracingMiddle object satisfies the backend interface
|
|
|
|
var _ logical.Backend = &backendTracingMiddleware{}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-01-18 21:49:20 +00:00
|
|
|
func (b *backendTracingMiddleware) HandleRequest(ctx context.Context, req *logical.Request) (resp *logical.Response, err error) {
|
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle request", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle request", "path", req.Path, "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.HandleRequest(ctx, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backendTracingMiddleware) SpecialPaths() *logical.Paths {
|
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("special paths", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("special paths", "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
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) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle existence check", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle existence check", "path", req.Path, "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.HandleExistenceCheck(ctx, req)
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backendTracingMiddleware) Cleanup(ctx context.Context) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("cleanup", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("cleanup", "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
b.next.Cleanup(ctx)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backendTracingMiddleware) InvalidateKey(ctx context.Context, key string) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("invalidate key", "key", key, "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("invalidate key", "key", key, "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
b.next.InvalidateKey(ctx, key)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backendTracingMiddleware) Setup(ctx context.Context, config *logical.BackendConfig) (err error) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("setup", "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("setup", "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
return b.next.Setup(ctx, config)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backendTracingMiddleware) Type() logical.BackendType {
|
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("type", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("type", "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.Type()
|
|
|
|
}
|