From 68efedfa88cd8b907aff2d101e88c7577014cb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Wed, 21 Oct 2020 09:10:54 +0200 Subject: [PATCH] App Plugins: Add backend support (#28272) * Add backend support for app plugins Co-authored-by: Marcus Efraimsson Co-authored-by: Arve Knudsen --- pkg/plugins/app_plugin.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/plugins/app_plugin.go b/pkg/plugins/app_plugin.go index a6cbc3e279e..495b3a56a6f 100644 --- a/pkg/plugins/app_plugin.go +++ b/pkg/plugins/app_plugin.go @@ -2,12 +2,15 @@ package plugins import ( "encoding/json" + "path/filepath" "strings" "github.com/gosimple/slug" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/plugins/backendplugin" + "github.com/grafana/grafana/pkg/plugins/backendplugin/grpcplugin" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util/errutil" ) type AppPluginCss struct { @@ -21,6 +24,8 @@ type AppPlugin struct { FoundChildPlugins []*PluginInclude `json:"-"` Pinned bool `json:"-"` + + Executable string `json:"executable,omitempty"` } // AppPluginRoute describes a plugin route that is defined in @@ -67,6 +72,15 @@ func (app *AppPlugin) Load(decoder *json.Decoder, base *PluginBase, backendPlugi return err } + if app.Backend { + cmd := ComposePluginStartCommand(app.Executable) + fullpath := filepath.Join(app.PluginDir, cmd) + factory := grpcplugin.NewBackendPlugin(app.Id, fullpath, grpcplugin.PluginStartFuncs{}) + if err := backendPluginManager.Register(app.Id, factory); err != nil { + return errutil.Wrapf(err, "failed to register backend plugin") + } + } + Apps[app.Id] = app return nil }