Feat: experimental sandbox mode for community plugins
This commit is contained in:
@@ -68,6 +68,10 @@ func MainApp() *cli.App {
|
||||
if cmd != nil {
|
||||
app.Commands = append(app.Commands, cmd)
|
||||
}
|
||||
sandbox := f.GetSandboxCommand()
|
||||
if sandbox != nil {
|
||||
app.Commands = append(app.Commands, sandbox)
|
||||
}
|
||||
}
|
||||
|
||||
return app
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/grpcplugin"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
goplugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/go-plugin/runner"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"go.opentelemetry.io/otel/trace/embedded"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/grpcplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
@@ -73,7 +73,7 @@ func newClientConfig(descriptor PluginDescriptor, env []string, logger log.Logge
|
||||
cmd := exec.Command(executablePath, descriptor.executableArgs...)
|
||||
cmd.Env = env
|
||||
|
||||
return &goplugin.ClientConfig{
|
||||
cfg := &goplugin.ClientConfig{
|
||||
Cmd: cmd,
|
||||
HandshakeConfig: handshake,
|
||||
VersionedPlugins: versionedPlugins,
|
||||
@@ -90,6 +90,12 @@ func newClientConfig(descriptor PluginDescriptor, env []string, logger log.Logge
|
||||
grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(newClientTracerProvider(tracer)))),
|
||||
},
|
||||
}
|
||||
|
||||
if descriptor.cmdEditor != nil {
|
||||
descriptor.cmdEditor(cfg.Cmd)
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func containerClientConfig(executablePath, containerImage, containerTag string, logger log.Logger, versionedPlugins map[int]goplugin.PluginSet, skipHostEnvVars bool, tracer trace.Tracer) *goplugin.ClientConfig {
|
||||
@@ -127,6 +133,7 @@ type PluginDescriptor struct {
|
||||
skipHostEnvVars bool
|
||||
managed bool
|
||||
containerMode containerModeOpts
|
||||
cmdEditor func(*exec.Cmd)
|
||||
versionedPlugins map[int]goplugin.PluginSet
|
||||
startRendererFn StartRendererFunc
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package grpcplugin
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc"
|
||||
@@ -52,6 +53,7 @@ type ProtoClientOpts struct {
|
||||
SkipHostEnvVars bool
|
||||
Logger log.Logger
|
||||
Tracer trace.Tracer
|
||||
CmdEditor func(*exec.Cmd)
|
||||
}
|
||||
|
||||
type ContainerModeOpts struct {
|
||||
@@ -73,6 +75,7 @@ func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) {
|
||||
image: opts.ContainerMode.Image,
|
||||
tag: opts.ContainerMode.Tag,
|
||||
},
|
||||
cmdEditor: opts.CmdEditor,
|
||||
skipHostEnvVars: opts.SkipHostEnvVars,
|
||||
},
|
||||
opts.Logger,
|
||||
|
||||
@@ -14,6 +14,7 @@ type BuildInfo struct {
|
||||
|
||||
type APIServerFactory interface {
|
||||
GetCLICommand(info BuildInfo) *cli.Command
|
||||
GetSandboxCommand() *cli.Command
|
||||
}
|
||||
|
||||
// NOOP
|
||||
@@ -26,3 +27,7 @@ type NoOpAPIServerFactory struct{}
|
||||
func (f *NoOpAPIServerFactory) GetCLICommand(info BuildInfo) *cli.Command {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *NoOpAPIServerFactory) GetSandboxCommand() *cli.Command {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user