-
Notifications
You must be signed in to change notification settings - Fork 311
/
helper.go
53 lines (48 loc) · 1.08 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package utils
import (
"os"
"os/exec"
"strings"
)
// CmdOutput stores the structure of kics output
type CmdOutput struct {
Output []string
Status int
}
// RunCommand executes the kics in a terminal
func RunCommand(args []string) (*CmdOutput, error) {
cmd := exec.Command(args[0], args[1:]...) //nolint
stdOutput, err := cmd.CombinedOutput()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
return &CmdOutput{
Output: strings.Split(string(stdOutput), "\n"),
Status: exitError.ExitCode(),
}, nil
}
return &CmdOutput{}, err
}
return &CmdOutput{
Output: strings.Split(string(stdOutput), "\n"),
Status: 0,
}, nil
}
// GetKICSBinaryPath gets the kics binary complete path
func GetKICSBinaryPath(path string) []string {
var rtnPath string
if path == "" {
rtnPath = os.Getenv("E2E_KICS_BINARY")
} else {
rtnPath = path
}
return []string{rtnPath}
}
// Contains returns if a string list contains an especific term
func Contains(list []string, searchTerm string) bool {
for _, a := range list {
if a == searchTerm {
return true
}
}
return false
}