Ver código fonte

expose the FormatAlert function to other packages (#2248)

blotus 2 anos atrás
pai
commit
7106d396dc
3 arquivos alterados com 20 adições e 3 exclusões
  1. 2 2
      pkg/csplugin/broker.go
  2. 1 1
      pkg/csplugin/utils.go
  3. 17 0
      pkg/csplugin/utils_js.go

+ 2 - 2
pkg/csplugin/broker.go

@@ -323,7 +323,7 @@ func (pb *PluginBroker) pushNotificationsToPlugin(pluginName string, alerts []*m
 		return nil
 		return nil
 	}
 	}
 
 
-	message, err := formatAlerts(pb.pluginConfigByName[pluginName].Format, alerts)
+	message, err := FormatAlerts(pb.pluginConfigByName[pluginName].Format, alerts)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
@@ -407,7 +407,7 @@ func getHandshake() (plugin.HandshakeConfig, error) {
 	return handshake, nil
 	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)
 	template, err := template.New("").Funcs(sprig.TxtFuncMap()).Funcs(funcMap()).Parse(format)
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err

+ 1 - 1
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
 package csplugin
 
 

+ 17 - 0
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
+}