Plugins: Use handler middleware from the SDK (#93445)
updates sdk to v0.251.0
This commit is contained in:
@@ -5,26 +5,23 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
)
|
||||
|
||||
const forwardIDHeaderName = "X-Grafana-Id"
|
||||
|
||||
// NewForwardIDMiddleware creates a new plugins.ClientMiddleware that will
|
||||
// set grafana id header on outgoing plugins.Client requests
|
||||
func NewForwardIDMiddleware() plugins.ClientMiddleware {
|
||||
return plugins.ClientMiddlewareFunc(func(next plugins.Client) plugins.Client {
|
||||
// NewForwardIDMiddleware creates a new backend.HandlerMiddleware that will
|
||||
// set grafana id header on outgoing backend.Handler requests
|
||||
func NewForwardIDMiddleware() backend.HandlerMiddleware {
|
||||
return backend.HandlerMiddlewareFunc(func(next backend.Handler) backend.Handler {
|
||||
return &ForwardIDMiddleware{
|
||||
baseMiddleware: baseMiddleware{
|
||||
next: next,
|
||||
},
|
||||
BaseHandler: backend.NewBaseHandler(next),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type ForwardIDMiddleware struct {
|
||||
baseMiddleware
|
||||
backend.BaseHandler
|
||||
}
|
||||
|
||||
func (m *ForwardIDMiddleware) applyToken(ctx context.Context, pCtx backend.PluginContext, req backend.ForwardHTTPHeaders) error {
|
||||
@@ -43,7 +40,7 @@ func (m *ForwardIDMiddleware) applyToken(ctx context.Context, pCtx backend.Plugi
|
||||
|
||||
func (m *ForwardIDMiddleware) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
if req == nil {
|
||||
return m.next.QueryData(ctx, req)
|
||||
return m.BaseHandler.QueryData(ctx, req)
|
||||
}
|
||||
|
||||
err := m.applyToken(ctx, req.PluginContext, req)
|
||||
@@ -51,12 +48,12 @@ func (m *ForwardIDMiddleware) QueryData(ctx context.Context, req *backend.QueryD
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.next.QueryData(ctx, req)
|
||||
return m.BaseHandler.QueryData(ctx, req)
|
||||
}
|
||||
|
||||
func (m *ForwardIDMiddleware) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||
if req == nil {
|
||||
return m.next.CallResource(ctx, req, sender)
|
||||
return m.BaseHandler.CallResource(ctx, req, sender)
|
||||
}
|
||||
|
||||
err := m.applyToken(ctx, req.PluginContext, req)
|
||||
@@ -64,12 +61,12 @@ func (m *ForwardIDMiddleware) CallResource(ctx context.Context, req *backend.Cal
|
||||
return err
|
||||
}
|
||||
|
||||
return m.next.CallResource(ctx, req, sender)
|
||||
return m.BaseHandler.CallResource(ctx, req, sender)
|
||||
}
|
||||
|
||||
func (m *ForwardIDMiddleware) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||
if req == nil {
|
||||
return m.next.CheckHealth(ctx, req)
|
||||
return m.BaseHandler.CheckHealth(ctx, req)
|
||||
}
|
||||
|
||||
err := m.applyToken(ctx, req.PluginContext, req)
|
||||
@@ -77,5 +74,5 @@ func (m *ForwardIDMiddleware) CheckHealth(ctx context.Context, req *backend.Chec
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.next.CheckHealth(ctx, req)
|
||||
return m.BaseHandler.CheckHealth(ctx, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user