mv and refactor (#46242)

This commit is contained in:
Will Browne 2022-03-04 15:26:35 +01:00 committed by GitHub
parent 5aa1713941
commit 7694b78456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 35 deletions

View File

@ -1,31 +0,0 @@
package plugins
import (
"fmt"
"runtime"
"strings"
)
func ComposePluginStartCommand(executable string) string {
os := strings.ToLower(runtime.GOOS)
arch := runtime.GOARCH
extension := ""
if os == "windows" {
extension = ".exe"
}
return fmt.Sprintf("%s_%s_%s%s", executable, os, strings.ToLower(arch), extension)
}
func ComposeRendererStartCommand() string {
os := strings.ToLower(runtime.GOOS)
arch := runtime.GOARCH
extension := ""
if os == "windows" {
extension = ".exe"
}
return fmt.Sprintf("%s_%s_%s%s", "plugin_start", os, strings.ToLower(arch), extension)
}

View File

@ -2,7 +2,10 @@ package provider
import (
"context"
"fmt"
"path/filepath"
"runtime"
"strings"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
@ -45,8 +48,7 @@ var RendererProvider PluginBackendProvider = func(_ context.Context, p *plugins.
if !p.IsRenderer() {
return nil
}
cmd := plugins.ComposeRendererStartCommand()
return grpcplugin.NewRendererPlugin(p.ID, filepath.Join(p.PluginDir, cmd),
return grpcplugin.NewRendererPlugin(p.ID, filepath.Join(p.PluginDir, rendererStartCmd()),
func(pluginID string, renderer pluginextensionv2.RendererPlugin, logger log.Logger) error {
p.Renderer = renderer
return nil
@ -56,6 +58,29 @@ var RendererProvider PluginBackendProvider = func(_ context.Context, p *plugins.
var DefaultProvider PluginBackendProvider = func(_ context.Context, p *plugins.Plugin) backendplugin.PluginFactoryFunc {
// TODO check for executable
cmd := plugins.ComposePluginStartCommand(p.Executable)
return grpcplugin.NewBackendPlugin(p.ID, filepath.Join(p.PluginDir, cmd))
return grpcplugin.NewBackendPlugin(p.ID, filepath.Join(p.PluginDir, pluginStartCmd(p.Executable)))
}
func pluginStartCmd(executable string) string {
os := strings.ToLower(runtime.GOOS)
arch := runtime.GOARCH
extension := ""
if os == "windows" {
extension = ".exe"
}
return fmt.Sprintf("%s_%s_%s%s", executable, os, strings.ToLower(arch), extension)
}
func rendererStartCmd() string {
os := strings.ToLower(runtime.GOOS)
arch := runtime.GOARCH
extension := ""
if os == "windows" {
extension = ".exe"
}
return fmt.Sprintf("%s_%s_%s%s", "plugin_start", os, strings.ToLower(arch), extension)
}