mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 21:43:48 +08:00
Plugins: Support Admission validation hooks (#87718)
This commit is contained in:
@ -18,6 +18,7 @@ type corePlugin struct {
|
||||
backend.CallResourceHandler
|
||||
backend.QueryDataHandler
|
||||
backend.StreamHandler
|
||||
backend.AdmissionHandler
|
||||
}
|
||||
|
||||
// New returns a new backendplugin.PluginFactoryFunc for creating a core (built-in) backendplugin.Plugin.
|
||||
@ -29,6 +30,7 @@ func New(opts backend.ServeOpts) backendplugin.PluginFactoryFunc {
|
||||
CheckHealthHandler: opts.CheckHealthHandler,
|
||||
CallResourceHandler: opts.CallResourceHandler,
|
||||
QueryDataHandler: opts.QueryDataHandler,
|
||||
AdmissionHandler: opts.AdmissionHandler,
|
||||
StreamHandler: opts.StreamHandler,
|
||||
}, nil
|
||||
}
|
||||
@ -124,3 +126,27 @@ func (cp *corePlugin) RunStream(ctx context.Context, req *backend.RunStreamReque
|
||||
}
|
||||
return plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (cp *corePlugin) MutateAdmission(ctx context.Context, req *backend.AdmissionRequest) (*backend.MutationResponse, error) {
|
||||
if cp.AdmissionHandler != nil {
|
||||
ctx = backend.WithGrafanaConfig(ctx, req.PluginContext.GrafanaConfig)
|
||||
return cp.AdmissionHandler.MutateAdmission(ctx, req)
|
||||
}
|
||||
return nil, plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (cp *corePlugin) ValidateAdmission(ctx context.Context, req *backend.AdmissionRequest) (*backend.ValidationResponse, error) {
|
||||
if cp.AdmissionHandler != nil {
|
||||
ctx = backend.WithGrafanaConfig(ctx, req.PluginContext.GrafanaConfig)
|
||||
return cp.AdmissionHandler.ValidateAdmission(ctx, req)
|
||||
}
|
||||
return nil, plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (cp *corePlugin) ConvertObject(ctx context.Context, req *backend.ConversionRequest) (*backend.ConversionResponse, error) {
|
||||
if cp.AdmissionHandler != nil {
|
||||
ctx = backend.WithGrafanaConfig(ctx, req.PluginContext.GrafanaConfig)
|
||||
return cp.AdmissionHandler.ConvertObject(ctx, req)
|
||||
}
|
||||
return nil, plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
sdktracing "github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
@ -145,6 +146,9 @@ func asBackendPlugin(svc any) backendplugin.PluginFactoryFunc {
|
||||
if healthHandler, ok := svc.(backend.CheckHealthHandler); ok {
|
||||
opts.CheckHealthHandler = healthHandler
|
||||
}
|
||||
if storageHandler, ok := svc.(backend.AdmissionHandler); ok {
|
||||
opts.AdmissionHandler = storageHandler
|
||||
}
|
||||
|
||||
if opts.QueryDataHandler != nil || opts.CallResourceHandler != nil ||
|
||||
opts.CheckHealthHandler != nil || opts.StreamHandler != nil {
|
||||
|
Reference in New Issue
Block a user