Plugins: Add baseMiddleware support (#87799)

This commit is contained in:
Ryan McKinley
2024-05-14 16:27:40 +03:00
committed by GitHub
parent 7a2fbad0c8
commit 62d326cf04
14 changed files with 109 additions and 246 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"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"
@ -18,7 +19,9 @@ import (
func NewOAuthTokenMiddleware(oAuthTokenService oauthtoken.OAuthTokenService) plugins.ClientMiddleware {
return plugins.ClientMiddlewareFunc(func(next plugins.Client) plugins.Client {
return &OAuthTokenMiddleware{
next: next,
baseMiddleware: baseMiddleware{
next: next,
},
oAuthTokenService: oAuthTokenService,
}
})
@ -30,8 +33,8 @@ const (
)
type OAuthTokenMiddleware struct {
baseMiddleware
oAuthTokenService oauthtoken.OAuthTokenService
next plugins.Client
}
func (m *OAuthTokenMiddleware) applyToken(ctx context.Context, pCtx backend.PluginContext, req interface{}) error {
@ -125,19 +128,3 @@ func (m *OAuthTokenMiddleware) CheckHealth(ctx context.Context, req *backend.Che
return m.next.CheckHealth(ctx, req)
}
func (m *OAuthTokenMiddleware) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
return m.next.CollectMetrics(ctx, req)
}
func (m *OAuthTokenMiddleware) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
return m.next.SubscribeStream(ctx, req)
}
func (m *OAuthTokenMiddleware) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
return m.next.PublishStream(ctx, req)
}
func (m *OAuthTokenMiddleware) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
return m.next.RunStream(ctx, req, sender)
}