forked from capnspacehook/taskmaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.go
127 lines (112 loc) · 3.53 KB
/
validate.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// +build windows
package taskmaster
import (
"errors"
"time"
)
var defaultTime = time.Time{}
func validateDefinition(def Definition) error {
var err error
if def.Actions == nil {
return ErrNoActions
}
if err = validateActions(def.Actions); err != nil {
return err
}
if err = validateTriggers(def.Triggers); err != nil {
return err
}
if def.Principal.UserID != "" && def.Principal.GroupID != "" {
return ErrInvalidPrinciple
}
return nil
}
func validateActions(actions []Action) error {
for _, action := range actions {
switch action.GetType() {
case TASK_ACTION_EXEC:
return nil
case TASK_ACTION_COM_HANDLER:
return nil
default:
return errors.New("invalid task action type")
}
}
return nil
}
func validateTriggers(triggers []Trigger) error {
for _, trigger := range triggers {
switch t := trigger.(type) {
case BootTrigger:
return nil
case DailyTrigger:
if t.GetStartBoundary() == defaultTime {
return errors.New("invalid DailyTrigger: StartBoundary is required")
} else if t.DayInterval > EveryOtherDay {
return errors.New("invalid DailyTrigger: invalid DayInterval")
}
return nil
case EventTrigger:
if t.Subscription == "" {
return errors.New("invalid EventTrigger: Subscription is required")
}
return nil
case IdleTrigger:
return nil
case LogonTrigger:
return nil
case MonthlyDOWTrigger:
if t.GetStartBoundary() == defaultTime {
return errors.New("invalid MonthlyDOWTrigger: StartBoundary is required")
} else if t.DaysOfWeek == 0 {
return errors.New("invalid MonthlyDOWTrigger: DaysOfWeek is required")
} else if t.DaysOfWeek > AllDays {
return errors.New("invalid MonthlyDOWTrigger: invalid DaysOfWeek")
} else if t.MonthsOfYear == 0 {
return errors.New("invalid MonthlyDOWTrigger: MonthsOfYear is required")
} else if t.MonthsOfYear > AllMonths {
return errors.New("invalid MonthlyDOWTrigger: invalid MonthsOfYear")
} else if t.WeeksOfMonth == 0 {
return errors.New("invalid MonthlyDOWTrigger: WeeksOfMonth is required")
} else if t.WeeksOfMonth > AllWeeks {
return errors.New("invalid MonthlyDOWTrigger: invalid WeeksOfMonth")
}
return nil
case MonthlyTrigger:
if t.GetStartBoundary() == defaultTime {
return errors.New("invalid MonthlyTrigger: StartBoundary is required")
} else if t.DaysOfMonth == 0 {
return errors.New("invalid MonthlyTrigger: DaysOfMonth is required")
} else if t.DaysOfMonth > AllDaysOfMonth {
return errors.New("invalid MonthlyTrigger: invalid DaysOfMonth")
} else if t.MonthsOfYear == 0 {
return errors.New("invalid MonthlyTrigger: MonthsOfYear is required")
} else if t.MonthsOfYear > AllMonths {
return errors.New("invalid MonthlyTrigger: invalid MonthsOfYear")
}
return nil
case RegistrationTrigger:
return nil
case SessionStateChangeTrigger:
return nil
case TimeTrigger:
return nil
case WeeklyTrigger:
if t.GetStartBoundary() == defaultTime {
return errors.New("invalid WeeklyTrigger: StartBoundary is required")
} else if t.DaysOfWeek == 0 {
return errors.New("invalid WeeklyTrigger: DaysOfWeek is required")
} else if t.DaysOfWeek > AllDays {
return errors.New("invalid WeeklyTrigger: invalid DaysOfWeek")
} else if t.WeekInterval == 0 {
return errors.New("invalid WeeklyTrigger: WeekInterval is required")
} else if t.WeekInterval > EveryOtherWeek {
return errors.New("invalid WeeklyTrigger: invalid WeekInterval")
}
return nil
default:
return errors.New("invalid task trigger type")
}
}
return nil
}