mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-04-27 11:42:55 +00:00
* First commit in this PR Added `scripting.active` as a helm value * added `scripting.active` to the config struct and the helm chart this array of strings will include the active script titles * updated the `active` filed in the script struct * go mod tidy * update go ver to 1.21.1
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package configStructs
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/kubeshark/kubeshark/misc"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type ScriptingConfig struct {
|
|
Env map[string]interface{} `yaml:"env" json:"env" default:"{}"`
|
|
Source string `yaml:"source" json:"source" default:""`
|
|
WatchScripts bool `yaml:"watchScripts" json:"watchScripts" default:"true"`
|
|
Active []string `yaml:"active" json:"active" default:"[]"`
|
|
Console bool `yaml:"console" json:"console" default:"true"`
|
|
}
|
|
|
|
func (config *ScriptingConfig) GetScripts() (scripts []*misc.Script, err error) {
|
|
if config.Source == "" {
|
|
return
|
|
}
|
|
|
|
var files []fs.DirEntry
|
|
files, err = os.ReadDir(config.Source)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, f := range files {
|
|
if f.IsDir() {
|
|
continue
|
|
}
|
|
|
|
var script *misc.Script
|
|
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)
|
|
if err != nil {
|
|
return
|
|
}
|
|
scripts = append(scripts, script)
|
|
|
|
log.Debug().Str("path", path).Msg("Found script:")
|
|
}
|
|
|
|
return
|
|
}
|