mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 17:42:12 +08:00
Plugins: Use handler middleware from the SDK (#93445)
updates sdk to v0.251.0
This commit is contained in:

committed by
GitHub

parent
54faa541c3
commit
b7a7f2bd62
@ -6,7 +6,6 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/util/proxyutil"
|
||||
@ -14,22 +13,20 @@ import (
|
||||
|
||||
const cookieHeaderName = "Cookie"
|
||||
|
||||
// NewCookiesMiddleware creates a new plugins.ClientMiddleware that will
|
||||
// forward incoming HTTP request Cookies to outgoing plugins.Client requests
|
||||
// NewCookiesMiddleware creates a new backend.HandlerMiddleware that will
|
||||
// forward incoming HTTP request Cookies to outgoing backend.Handler requests
|
||||
// if the datasource has enabled forwarding of cookies (keepCookies).
|
||||
func NewCookiesMiddleware(skipCookiesNames []string) plugins.ClientMiddleware {
|
||||
return plugins.ClientMiddlewareFunc(func(next plugins.Client) plugins.Client {
|
||||
func NewCookiesMiddleware(skipCookiesNames []string) backend.HandlerMiddleware {
|
||||
return backend.HandlerMiddlewareFunc(func(next backend.Handler) backend.Handler {
|
||||
return &CookiesMiddleware{
|
||||
baseMiddleware: baseMiddleware{
|
||||
next: next,
|
||||
},
|
||||
BaseHandler: backend.NewBaseHandler(next),
|
||||
skipCookiesNames: skipCookiesNames,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type CookiesMiddleware struct {
|
||||
baseMiddleware
|
||||
backend.BaseHandler
|
||||
skipCookiesNames []string
|
||||
}
|
||||
|
||||
@ -87,7 +84,7 @@ func (m *CookiesMiddleware) applyCookies(ctx context.Context, pCtx backend.Plugi
|
||||
|
||||
func (m *CookiesMiddleware) 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.applyCookies(ctx, req.PluginContext, req)
|
||||
@ -95,12 +92,12 @@ func (m *CookiesMiddleware) QueryData(ctx context.Context, req *backend.QueryDat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.next.QueryData(ctx, req)
|
||||
return m.BaseHandler.QueryData(ctx, req)
|
||||
}
|
||||
|
||||
func (m *CookiesMiddleware) 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.applyCookies(ctx, req.PluginContext, req)
|
||||
@ -108,12 +105,12 @@ func (m *CookiesMiddleware) CallResource(ctx context.Context, req *backend.CallR
|
||||
return err
|
||||
}
|
||||
|
||||
return m.next.CallResource(ctx, req, sender)
|
||||
return m.BaseHandler.CallResource(ctx, req, sender)
|
||||
}
|
||||
|
||||
func (m *CookiesMiddleware) 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.applyCookies(ctx, req.PluginContext, req)
|
||||
@ -121,5 +118,5 @@ func (m *CookiesMiddleware) CheckHealth(ctx context.Context, req *backend.CheckH
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.next.CheckHealth(ctx, req)
|
||||
return m.BaseHandler.CheckHealth(ctx, req)
|
||||
}
|
||||
|
Reference in New Issue
Block a user