File tree 1 file changed +5
-3
lines changed 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,19 @@ import (
9
9
"github.com/Masterminds/semver/v3"
10
10
"github.com/go-playground/validator/v10"
11
11
"github.com/google/uuid"
12
+ "github.com/robfig/cron/v3"
12
13
13
14
"github.com/hatchet-dev/hatchet/internal/cel"
14
15
"github.com/hatchet-dev/hatchet/pkg/client/types"
15
16
)
16
17
17
18
var NameRegex = regexp .MustCompile ("^[a-zA-Z0-9\\ .\\ -_]+$" ) //nolint:gosimple
18
19
19
- var CronRegex = regexp .MustCompile (`(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})` ) //nolint:gosimple
20
-
21
20
func newValidator () * validator.Validate {
22
21
validate := validator .New ()
23
22
24
23
celParser := cel .NewCELParser ()
24
+ cronParser := cron .NewParser (cron .Minute | cron .Hour | cron .Dom | cron .Month | cron .Dow )
25
25
26
26
_ = validate .RegisterValidation ("hatchetName" , func (fl validator.FieldLevel ) bool {
27
27
return NameRegex .MatchString (fl .Field ().String ())
@@ -36,7 +36,9 @@ func newValidator() *validator.Validate {
36
36
})
37
37
38
38
_ = validate .RegisterValidation ("cron" , func (fl validator.FieldLevel ) bool {
39
- return CronRegex .MatchString (fl .Field ().String ())
39
+ _ , err := cronParser .Parse (fl .Field ().String ())
40
+
41
+ return err == nil
40
42
})
41
43
42
44
_ = validate .RegisterValidation ("actionId" , func (fl validator.FieldLevel ) bool {
You can’t perform that action at this time.
0 commit comments