From 7106d396dc53bc1c1e3f183281c73dae9dc409f8 Mon Sep 17 00:00:00 2001 From: blotus Date: Tue, 25 Jul 2023 09:55:39 +0200 Subject: [PATCH] expose the FormatAlert function to other packages (#2248) --- pkg/csplugin/broker.go | 4 ++-- pkg/csplugin/utils.go | 2 +- pkg/csplugin/utils_js.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 pkg/csplugin/utils_js.go diff --git a/pkg/csplugin/broker.go b/pkg/csplugin/broker.go index b1bd54dfd..208ce9336 100644 --- a/pkg/csplugin/broker.go +++ b/pkg/csplugin/broker.go @@ -323,7 +323,7 @@ func (pb *PluginBroker) pushNotificationsToPlugin(pluginName string, alerts []*m return nil } - message, err := formatAlerts(pb.pluginConfigByName[pluginName].Format, alerts) + message, err := FormatAlerts(pb.pluginConfigByName[pluginName].Format, alerts) if err != nil { return err } @@ -407,7 +407,7 @@ func getHandshake() (plugin.HandshakeConfig, error) { return handshake, nil } -func formatAlerts(format string, alerts []*models.Alert) (string, error) { +func FormatAlerts(format string, alerts []*models.Alert) (string, error) { template, err := template.New("").Funcs(sprig.TxtFuncMap()).Funcs(funcMap()).Parse(format) if err != nil { return "", err diff --git a/pkg/csplugin/utils.go b/pkg/csplugin/utils.go index 5e19dee38..216a079d4 100644 --- a/pkg/csplugin/utils.go +++ b/pkg/csplugin/utils.go @@ -1,4 +1,4 @@ -//go:build linux || freebsd || netbsd || openbsd || solaris || !windows +//go:build linux || freebsd || netbsd || openbsd || solaris || (!windows && !js) package csplugin diff --git a/pkg/csplugin/utils_js.go b/pkg/csplugin/utils_js.go new file mode 100644 index 000000000..e6cccab4b --- /dev/null +++ b/pkg/csplugin/utils_js.go @@ -0,0 +1,17 @@ +package csplugin + +import "os/exec" + +//All functions are empty, just to make the code compile when targeting js/wasm + +func (pb *PluginBroker) CreateCmd(binaryPath string) (*exec.Cmd, error) { + return nil, nil +} + +func getPluginTypeAndSubtypeFromPath(path string) (string, string, error) { + return "", "", nil +} + +func pluginIsValid(path string) error { + return nil +}