Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac4d723

Browse files
authored
fix: add validation to cron (#159)
1 parent9495777 commitac4d723

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ require (
4646
github.com/mitchellh/reflectwalkv1.0.2// indirect
4747
github.com/oklog/runv1.0.0// indirect
4848
github.com/pmezard/go-difflibv1.0.0// indirect
49+
github.com/robfig/cron/v3v3.0.1// indirect
4950
github.com/rogpeppe/go-internalv1.8.0// indirect
5051
github.com/vmihailenco/msgpackv4.0.4+incompatible// indirect
5152
github.com/vmihailenco/msgpack/v4v4.3.12// indirect

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
143143
github.com/pkg/errorsv0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
144144
github.com/pmezard/go-difflibv1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
145145
github.com/pmezard/go-difflibv1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
146+
github.com/robfig/cron/v3v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
147+
github.com/robfig/cron/v3v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
146148
github.com/rogpeppe/go-internalv1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
147149
github.com/rogpeppe/go-internalv1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
148150
github.com/rogpeppe/go-internalv1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=

‎provider/script.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/google/uuid"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
11+
"github.com/robfig/cron/v3"
1012
)
1113

14+
varScriptCRONParser=cron.NewParser(cron.Second|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.DowOptional|cron.Descriptor)
15+
1216
funcscriptResource()*schema.Resource {
1317
return&schema.Resource{
1418
Description:"Use this resource to run a script from an agent.",
@@ -56,6 +60,17 @@ func scriptResource() *schema.Resource {
5660
Type:schema.TypeString,
5761
Optional:true,
5862
Description:"The cron schedule to run the script on. This is a cron expression.",
63+
ValidateFunc:func(iinterface{},sstring) ([]string, []error) {
64+
v,ok:=i.(string)
65+
if!ok {
66+
return []string{}, []error{fmt.Errorf("got type %T instead of string",i)}
67+
}
68+
_,err:=ScriptCRONParser.Parse(v)
69+
iferr!=nil {
70+
return []string{}, []error{fmt.Errorf("%s is not a valid cron expression: %w",v,err)}
71+
}
72+
returnnil,nil
73+
},
5974
},
6075
"start_blocks_login": {
6176
Type:schema.TypeBool,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp