mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-09 14:31:07 +00:00
Ensure scripting
command watched only JS files
This commit is contained in:
@@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
@@ -168,6 +169,10 @@ func watchScripts(provider *kubernetes.Provider, block bool) {
|
|||||||
select {
|
select {
|
||||||
// watch for events
|
// watch for events
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
|
if !strings.HasSuffix(event.Name, "js") {
|
||||||
|
log.Info().Str("file", event.Name).Msg("Ignoring file")
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch event.Op {
|
switch event.Op {
|
||||||
case fsnotify.Create:
|
case fsnotify.Create:
|
||||||
script, err := misc.ReadScriptFile(event.Name)
|
script, err := misc.ReadScriptFile(event.Name)
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/kubeshark/kubeshark/misc"
|
"github.com/kubeshark/kubeshark/misc"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -33,6 +34,10 @@ func (config *ScriptingConfig) GetScripts() (scripts []*misc.Script, err error)
|
|||||||
|
|
||||||
var script *misc.Script
|
var script *misc.Script
|
||||||
path := filepath.Join(config.Source, f.Name())
|
path := filepath.Join(config.Source, f.Name())
|
||||||
|
if !strings.HasSuffix(path, ".js") {
|
||||||
|
log.Info().Str("path", path).Msg("Skipping non-JS file")
|
||||||
|
continue
|
||||||
|
}
|
||||||
script, err = misc.ReadScriptFile(path)
|
script, err = misc.ReadScriptFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user