This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckparser.go
56 lines (50 loc) · 2.03 KB
/
checkparser.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
54
55
56
package checkparser
import (
"errors"
"strings"
"github.com/kudelskisecurity/youshallnotpass/pkg/checks"
"github.com/kudelskisecurity/youshallnotpass/pkg/checks/datetime"
"github.com/kudelskisecurity/youshallnotpass/pkg/checks/imagehash"
"github.com/kudelskisecurity/youshallnotpass/pkg/checks/mfarequired"
"github.com/kudelskisecurity/youshallnotpass/pkg/checks/scripthash"
"github.com/kudelskisecurity/youshallnotpass/pkg/config"
)
var ErrUnknownCheckNameError = errors.New("unknown check name")
func ParseChecks(configs []config.CheckConfig, jobName string, image string, scriptLines []string, checkType string, ciPlatform string) ([]checks.Check, error) {
var stage uint
if checkType == "image" {
stage = checks.ImageCheck
} else if checkType == "script" {
stage = checks.ScriptCheck
} else {
stage = checks.All
}
var performChecks []checks.Check
for _, config := range configs {
switch strings.ToLower(config.Name) {
case "scripthash":
scriptHashCheck := scripthash.NewScriptHashCheck(config, jobName, scriptLines)
if scriptHashCheck.IsValidForPlatform(ciPlatform) && scriptHashCheck.IsValidForCheckType(stage) {
performChecks = append(performChecks, &scriptHashCheck)
}
case "imagehash":
imageHashCheck := imagehash.NewImageHashCheck(config, jobName, image)
if imageHashCheck.IsValidForPlatform(ciPlatform) && imageHashCheck.IsValidForCheckType(stage) {
performChecks = append(performChecks, &imageHashCheck)
}
case "mfarequired":
mfaRequiredCheck := mfarequired.NewMfaRequiredCheck(config, jobName)
if mfaRequiredCheck.IsValidForPlatform(ciPlatform) && mfaRequiredCheck.IsValidForCheckType(stage) {
performChecks = append(performChecks, &mfaRequiredCheck)
}
case "datetimecheck":
dateTimeCheck := datetime.NewDateTimeCheck(config, jobName)
if dateTimeCheck.IsValidForPlatform(ciPlatform) && dateTimeCheck.IsValidForCheckType(stage) {
performChecks = append(performChecks, &dateTimeCheck)
}
default:
return performChecks, ErrUnknownCheckNameError
}
}
return performChecks, nil
}